﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Inventory;
using Styx.CommonBot.Routines;
using Styx.Helpers;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;
using Action = Styx.TreeSharp.Action;
using CommonBehaviors.Actions;
using System.Diagnostics;

namespace TuanHA_Combat_Routine
{
    public partial class Classname
    {
        #region AntiMagicShell@

        private static DateTime LastShield;

        private static Composite AntiMagicShell()
        {
            return new Decorator(ret => (((THSettings.Instance.AntiMagicShell && ((LastShield + TimeSpan.FromMilliseconds(3000.0)) < DateTime.Now)) && (Me.Combat && CurrentTargetAttackable(30.0, false, false))) && (!MeHasAura("Anti-Magic Zone") && (Me.HealthPercent <= THSettings.Instance.AntiMagicShellHP))) && CanCastCheck("Anti-Magic Shell", true), new Styx.TreeSharp.Action(delegate(object ret)
            {
                LastShield = DateTime.Now;
                CastSpell("Anti-Magic Shell", Me, "AntiMagicShellHP");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region AntiMagicShellEnemy@

        private static Composite AntiMagicShellEnemy()
        {
            return new Decorator(ret => (((THSettings.Instance.AntiMagicShellEnemy && ((LastShield + TimeSpan.FromMilliseconds(3000.0)) < DateTime.Now)) && (Me.Combat && CurrentTargetAttackable(10.0, false, false))) && ((Me.CurrentTarget.PowerType == WoWPowerType.Mana) && (Me.CurrentTarget.HealthPercent <= THSettings.Instance.AntiMagicShellEnemyHP))) && CanCastCheck("Anti-Magic Shell", true), new Styx.TreeSharp.Action(delegate(object ret)
            {
                LastShield = DateTime.Now;
                CastSpell("Anti-Magic Shell", Me, "AntiMagicShellEnemyHP");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region AntiMagicShellLichborne@

        private static bool HasPaladinPriestAround()
        {
            return NearbyUnFriendlyPlayers.Any<WoWUnit>(unit => ((((BasicCheck(unit) && (unit.Distance < 31.0)) && ((unit.Class == WoWClass.Paladin) || (unit.Class == WoWClass.Priest))) && !DebuffCC(unit)) && InLineOfSpellSightCheck(unit)));
        }

        private static Composite AntiMagicShellLichborne()
        {
            return new Decorator(ret => ((((THSettings.Instance.AntiMagicShellLichborne && ((LastShield + TimeSpan.FromMilliseconds(3000.0)) < DateTime.Now)) && (Me.Combat && MeHasAura("Lichborne"))) && (InArena || InBattleground)) && CanCastCheck("Anti-Magic Shell", true)) && HasPaladinPriestAround(), new Styx.TreeSharp.Action(delegate(object ret)
            {
                LastShield = DateTime.Now;
                CastSpell("Anti-Magic Shell", Me, "AntiMagicShellLichborne");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region AntiMagicShellDebuff@

        private static Composite AntiMagicShellDebuff()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.AntiMagicShellDebuff || ((LastShield + TimeSpan.FromMilliseconds(3000.0)) >= DateTime.Now)) || (!Me.Combat || MeHasAura("Anti-Magic Zone"))) || ((CountDebuffMagic(Me) < THSettings.Instance.AntiMagicShellDebuffNumber) && (!MeHasAura(0x1c138) || (Me.GetAuraById(0x1c138).StackCount < 2))))
                {
                    return false;
                }
                return CanCastCheck("Anti-Magic Shell", true);
            }, new Styx.TreeSharp.Action(delegate(object ret)
            {
                LastShield = DateTime.Now;
                CastSpell("Anti-Magic Shell", Me, "AntiMagicShellDebuff");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region AntiMagicShellCaster@

        private static Composite AntiMagicShellCaster()
        {
            return new Decorator(ret => (((THSettings.Instance.AntiMagicShellCaster && ((LastShield + TimeSpan.FromMilliseconds(3000.0)) < DateTime.Now)) && (Me.Combat && !MeHasAura("Anti-Magic Zone"))) && CanCastCheck("Anti-Magic Shell", true)) && (CountMagicDPSTarget(Me) >= THSettings.Instance.AntiMagicShellCasterNumber), new Styx.TreeSharp.Action(delegate(object ret)
            {
                LastShield = DateTime.Now;
                CastSpell("Anti-Magic Shell", Me, "AntiMagicShellCaster");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region AntiMagicZone@

        private static Composite AntiMagicZone()
        {
            return new Decorator(ret => (((THSettings.Instance.AntiMagicZone && ((LastShield + TimeSpan.FromMilliseconds(3000.0)) < DateTime.Now)) && (!IsMoving(Me) && Me.Combat)) && ((CurrentTargetAttackable(30.0, false, false) && !MeHasAura("Anti-Magic Shell")) && (HealWeight(Me) <= THSettings.Instance.AntiMagicZoneHP))) && CanCastCheck("Anti-Magic Zone", true), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastShield = DateTime.Now;
                LastCastontheGround = DateTime.Now;
                CastSpell("Anti-Magic Zone", Me, "AntiMagicZone");
                new Wait(TimeSpan.FromMilliseconds(1000.0), ret => Me.CurrentPendingCursorSpell != null, new ActionAlwaysSucceed());
                LastCastontheGroundPosition = CalculateDropLocation(Me);
                SpellManager.ClickRemoteLocation(LastCastontheGroundPosition);
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region AntiMagicZoneDebuff@

        private static Composite AntiMagicZoneDebuff()
        {
            return new Decorator(ret => (((THSettings.Instance.AntiMagicZoneDebuff && ((LastShield + TimeSpan.FromMilliseconds(3000.0)) < DateTime.Now)) && (!IsMoving(Me) && Me.Combat)) && (!MeHasAura("Anti-Magic Shell") && (CountDebuffMagic(Me) >= THSettings.Instance.AntiMagicZoneDebuffNumber))) && CanCastCheck("Anti-Magic Zone", true), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastShield = DateTime.Now;
                LastCastontheGround = DateTime.Now;
                CastSpell("Anti-Magic Zone", Me, "AntiMagicZoneDebuff");
                new Wait(TimeSpan.FromMilliseconds(1000.0), ret => Me.CurrentPendingCursorSpell != null, new ActionAlwaysSucceed());
                LastCastontheGroundPosition = CalculateDropLocation(Me);
                SpellManager.ClickRemoteLocation(LastCastontheGroundPosition);
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region AntiMagicZoneCaster@

        private static Composite AntiMagicZoneCaster()
        {
            return new Decorator(ret => (((THSettings.Instance.AntiMagicShellCaster && ((LastShield + TimeSpan.FromMilliseconds(3000.0)) < DateTime.Now)) && (!IsMoving(Me) && Me.Combat)) && (!MeHasAura("Anti-Magic Shell") && CanCastCheck("Anti-Magic Zone", true))) && (CountMagicDPSTarget(Me) >= THSettings.Instance.AntiMagicShellCasterNumber), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastShield = DateTime.Now;
                LastCastontheGround = DateTime.Now;
                CastSpell("Anti-Magic Zone", Me, "AntiMagicZoneCaster");
                new Wait(TimeSpan.FromMilliseconds(1000.0), ret => Me.CurrentPendingCursorSpell != null, new ActionAlwaysSucceed());
                LastCastontheGroundPosition = CalculateDropLocation(Me);
                SpellManager.ClickRemoteLocation(LastCastontheGroundPosition);
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region ArcaneTorrent@

        private static WoWUnit UnitArcaneTorrent;

        private static bool GetUnitArcaneTorrent()
        {
            UnitArcaneTorrent = null;
            if (InBattleground || InArena)
            {
                UnitArcaneTorrent = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && InterruptCheck(unit, (double)THSettings.Instance.MindFreezeInterruptMs, false)) && Attackable(unit, 8));
            }
            else
            {
                UnitArcaneTorrent = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && ((InProvingGrounds || unit.Combat) && (FarFriendlyPlayers.Contains(unit.CurrentTarget) && InterruptCheck(unit, (double)THSettings.Instance.MindFreezeInterruptMs, false)))) && Attackable(unit, 8));
            }
            return BasicCheck(UnitArcaneTorrent);
        }

        private static void ArcaneTorrentVoid()
        {
            if (THSettings.Instance.AutoRacial &&
                LastInterrupt < DateTime.Now &&
                CanCastCheck("Arcane Torrent", true) &&
                GetUnitArcaneTorrent())
            {
                if (Me.IsCasting)
                {
                    SpellManager.StopCasting();
                }

                //new Wait(TimeSpan.FromMilliseconds(2000.0), ret => UnitArcaneTorrent.IsCasting && (UnitArcaneTorrent.CurrentCastTimeLeft.TotalMilliseconds > (THSettings.Instance.MindFreezeInterruptMs + MyLatency)), new ActionAlwaysSucceed());
                while (UnitArcaneTorrent.CurrentCastTimeLeft.TotalMilliseconds > THSettings.Instance.MindFreezeInterruptMs)
                {
                    Styx.Common.Logging.Write("Waiting for Arcane Torrent");
                }

                if (UnitArcaneTorrent.IsCasting)
                {
                    CastSpell("Arcane Torrent", Me, "Arcane Torrent");
                    LastInterrupt = DateTime.Now + TimeSpan.FromMilliseconds(1500);
                }
            }
        }

        #endregion

        #region AttackOOC@

        //private static Composite StopAttackOOC()
        //{
        //    return new Decorator(
        //        ret =>
        //        !THSettings.Instance.AttackOOC &&
        //        !Me.Combat,
        //        new Action(
        //            ret =>
        //                {
        //                    Logging.Write("Stop Attack Out of Combat");
        //                    if (Me.IsAutoAttacking)
        //                    {
        //                        Lua.DoString("RunMacroText('/stopattack');");
        //                    }
        //                    return RunStatus.Success;
        //                })
        //        );
        //}

        #endregion

        #region AttackASAP@

        private static WoWUnit UnitAttackASAP;

        private static bool GetUnitAttackASAP()
        {
            if (!InArena && !InBattleground)
            {
                return false;
            }
            UnitAttackASAP = null;
            UnitAttackASAP = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(delegate(WoWUnit unit)
            {
                if ((!BasicCheck(unit) || !FacingOverride(unit)) || (!Attackable(unit, 30) || !unit.IsTotem))
                {
                    return false;
                }
                if ((((unit.Entry != 0xcf0e) && (unit.Entry != 0xec91)) && ((unit.Entry != 0xa46) && (unit.Entry != 0xe945))) && ((unit.Entry != 0x28e3) && (unit.Entry != 0xe974)))
                {
                    return unit.Entry == 0xef3d;
                }
                return true;
            });
            return BasicCheck(UnitAttackASAP);
        }

        private static Composite AttackASAP()
        {
            return new PrioritySelector(new Composite[] { new Decorator(ret => (((THSettings.Instance.AttackASAP && ((HoldPetAction + TimeSpan.FromMilliseconds(4000.0)) < DateTime.Now)) && (Me.GotAlivePet && !DebuffCC(Me.Pet))) && !DebuffRoot(Me.Pet)) && GetUnitAttackASAP(), new Styx.TreeSharp.Action(delegate (object ret) {
                if (PetCanCastAction("Leap"))
                {
                    PetCastAction("Leap", UnitAttackASAP);
                }
                PetCastAction("Attack", UnitAttackASAP);
                HoldPetAction = DateTime.Now;
                return RunStatus.Failure;
            })), new Decorator(ret => (THSettings.Instance.AttackASAP && CanCastCheck("Icy Touch", false)) && GetUnitAttackASAP(), new Styx.TreeSharp.Action(delegate (object ret) {
                SafelyFacingTarget(UnitAttackASAP);
                CastSpell("Icy Touch", UnitAttackASAP, "Icy Touch: Flag Capper or Totem");
            })), new Decorator(ret => (THSettings.Instance.AttackASAP && CanCastCheck("Death Coil", false)) && GetUnitAttackASAP(), new Styx.TreeSharp.Action(delegate (object ret) {
                SafelyFacingTarget(UnitAttackASAP);
                CastSpell("Death Coil", UnitAttackASAP, "Death Coil: Flag Capper or Totem");
            })) });
        }

        #endregion

        #region Asphyxiate@

        private static bool GetUnitAsphyxiateInterrupt()
        {
            UnitInterrupt = null;
            if (InBattleground || InArena)
            {
                UnitInterrupt = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && ((!InvulnerableSpell(unit) && !InvulnerableStun(unit)) && (FacingOverride(unit) && InterruptCheck(unit, (double)THSettings.Instance.StrangulateInterruptMs, true)))) && Attackable(unit, 30));
            }
            else
            {
                UnitInterrupt = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && ((InProvingGrounds || unit.Combat) && (FacingOverride(unit) && FarFriendlyPlayers.Contains(unit.CurrentTarget)))) && InterruptCheck(unit, (double)THSettings.Instance.StrangulateInterruptMs, true));
            }
            return BasicCheck(UnitInterrupt);
        }

        private static void AsphyxiateVoid()
        {
            if (THSettings.Instance.StrangulateInterrupt &&
                LastInterrupt + TimeSpan.FromMilliseconds(1000) < DateTime.Now &&
                Me.Combat &&
                CanCastCheck("Asphyxiate", true) &&
                GetUnitAsphyxiateInterrupt())

            {
                if (Me.IsCasting)
                {
                    SpellManager.StopCasting();
                }
                FacingDelay = DateTime.Now;
                if (THSettings.Instance.AutoFace &&
                    FacingDelay + TimeSpan.FromMilliseconds(100) > DateTime.Now &&
                    !Me.IsFacing(UnitInterrupt))
                {
                    Me.SetFacing(UnitInterrupt);
                }
                //new Wait(TimeSpan.FromMilliseconds(2000.0), ret => UnitInterrupt.IsCasting && (UnitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > (THSettings.Instance.MindFreezeInterruptMs + MyLatency)), new ActionAlwaysSucceed());
                while (UnitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > THSettings.Instance.StrangulateInterruptMs)
                {
                    Styx.Common.Logging.Write("Waiting for Asphyxiate");
                }
                if (UnitInterrupt.IsCasting)
                {
                    CastSpell("Asphyxiate", UnitInterrupt, "AsphyxiateVoid");
                    LastInterrupt = DateTime.Now;
                }
            }
        }

        #endregion

        #region AutoTarget@

        private static DateTime LastAutoTarget;

        private static Composite AutoTarget()
        {
            return new Action(delegate
                {
                    if (!THSettings.Instance.AutoTarget ||
                        LastAutoTarget > DateTime.Now)
                    {
                        return RunStatus.Failure;
                    }

                    if (Me.CurrentTarget != null && Me.CurrentTarget.IsValid &&
                        !CurrentTargetAttackableNoLoS(50) &&
                        GetBestTarget() &&
                        UnitBestTarget != null &&
                        UnitBestTarget.IsValid &&
                        Me.CurrentTarget != UnitBestTarget)
                    {
                        UnitBestTarget.Target();
                        Logging.Write(LogLevel.Diagnostic, "Switch to Best Unit");
                        LastAutoTarget = DateTime.Now + TimeSpan.FromMilliseconds(1000);
                        return RunStatus.Failure;
                    }

                    if (Me.CurrentTarget == null &&
                        GetBestTarget() &&
                        UnitBestTarget != null &&
                        UnitBestTarget.IsValid)
                    {
                        UnitBestTarget.Target();
                        Logging.Write(LogLevel.Diagnostic, "Target  Best Unit");
                        LastAutoTarget = DateTime.Now + TimeSpan.FromMilliseconds(1000);
                        return RunStatus.Failure;
                    }
                    LastAutoTarget = DateTime.Now + TimeSpan.FromMilliseconds(1000);
                    return RunStatus.Failure;
                });
        }

        #endregion

        #region BoneShield@

        private static Composite BoneShield()
        {
            return new Decorator(ret => ((THSettings.Instance.BoneShield && !MeHasAura("Bone Shield")) && !Me.InVehicle) && CanCastCheck("Bone Shield", true), new Styx.TreeSharp.Action(delegate(object ret)
            {
                CastSpell("Bone Shield", Me, "");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region BloodBoilRefreshDebuffAoE@

        private static Composite BloodBoilRefreshDebuffAoE()
        {
            return new Decorator(ret => (((THSettings.Instance.BloodBoil && SpellManager.HasSpell("Scarlet Fever")) && (CurrentTargetAttackable(10.0, false, false) && CanCastCheck("Blood Boil", false))) && ((HasEnemyDontHaveBloodPlague() && HasEnemyHaveBloodPlague()) && (HasEnemyDontHaveFrostFever() && HasEnemyHaveFrostFever()))) && !HasEnemyNearGotCCBreakonDamge(Me.CurrentTarget, (float)(10 + GlyphprivateofPestilenceBonus)), new Action(delegate
            {
                CastSpell("Blood Boil", Me, "BloodBoilRefreshDebuffAoE");
                LastSpreadDiseases = DateTime.Now + TimeSpan.FromMilliseconds(2000.0);
            }));
        }

        #endregion

        #region BloodPresence@

        private static DateTime PresenceSwapLast = DateTime.Now;

        private static Composite BloodPresenceSwap()
        {
            return new Decorator(
                ret => (//THSettings.Instance.BloodPresence &&
                        THSettings.Instance.AutoPrecence &&
                        (PresenceSwapLast + TimeSpan.FromMilliseconds((double)THSettings.Instance.PresenceSwapTimeout)) < DateTime.Now && 
                        !MeHasAura("Blood Presence") && 
                        (HealWeight(Me) <= THSettings.Instance.BloodPresenceHP || CountDPSTarget(Me) > 1 || !HasHealerWithMe()) && 
                         //((InArena || InBattleground) && (CountDPSTarget(Me) > 1 || !HasHealerWithMe()))) && 
                        
                         CanCastCheck("Blood Presence", false)), new Styx.TreeSharp.Action(delegate(object param0)
            {
                PresenceSwapLast = DateTime.Now;
                CastSpell("Blood Presence", Me, "BloodPresence");
            }));
        }

        #endregion

        #region BloodBoilProc@

        private static Composite BloodBoilProc()
        {
            return new Decorator(ret => (((THSettings.Instance.BloodBoil && ((LastProc + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && (MeHasAura(0x13cf5) && CurrentTargetAttackable(10.0, false, false))) && (MyAura("Frost Fever", Me.CurrentTarget) && MyAura("Blood Plague", Me.CurrentTarget))) && CanCastCheck("Blood Boil", false), new Styx.TreeSharp.Action(delegate(object ret)
            {
                LastProc = DateTime.Now;
                CastSpell("Blood Boil", Me, "BloodBoilProc");
            }));
        }

        #endregion

        #region BloodBoil4Unit@

        private static Composite BloodBoil4Unit()
        {
            return new Decorator(ret => (THSettings.Instance.BloodBoil && CanCastCheck("Blood Boil", false)) && (CountEnemyNear(Me, 15f) >= 4.0), new Styx.TreeSharp.Action(delegate(object ret)
            {
                CastSpell("Blood Boil", Me, "BloodBoil4Unit");
            }));
        }

        #endregion

        #region BloodBoilRoilingBlood@

        private static WoWUnit BestBloodBoilRoilingBloodTarget;

        private static bool GetBestBloodBoilRoilingBloodTarget()
        {
            BestBloodBoilRoilingBloodTarget = null;
            BestBloodBoilRoilingBloodTarget = (from unit in NearbyUnFriendlyUnits.Where<WoWUnit>(new Func<WoWUnit, bool>(Classname.BasicCheck))
                                               orderby MyAuraTimeLeft("Frost Fever", unit), MyAuraTimeLeft("Blood Plague", unit)
                                               select unit).FirstOrDefault<WoWUnit>(unit => (MyAura("Frost Fever", unit) && MyAura("Blood Plague", unit)) && Attackable(unit, 5));
            return BasicCheck(BestBloodBoilRoilingBloodTarget);
        }
        
        private static DateTime LastSpreadDiseases;
        private static Composite BloodBoilRoilingBlood()
        {
            return new Decorator(ret => (((THSettings.Instance.BloodBoil && (LastSpreadDiseases < DateTime.Now)) && (CanUseDeathRune() || (Me.BloodRuneCount > 0))) && ((SpellManager.HasSpell("Roiling Blood") && CanCastCheck("Blood Boil", false)) && (HasEnemyDontHaveBloodPlagueorFrostFever() && !HasEnemyNearGotCCBreakonDamge(Me.CurrentTarget, (float)(10 + GlyphprivateofPestilenceBonus))))) && GetBestBloodBoilRoilingBloodTarget(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Blood Boil", BestBloodBoilRoilingBloodTarget, "BloodBoilRoilingBlood");
                LastSpreadDiseases = DateTime.Now + TimeSpan.FromMilliseconds(2000.0);
            }));
        }

        #endregion

        #region BloodBoilRoilingBloodConversion@
        private static Composite BloodBoilRoilingBloodConversion()
        {
            return new Decorator(ret => ((((THSettings.Instance.BloodBoil && THSettings.Instance.NecroticStrikeStack) && ((LastSpreadDiseases < DateTime.Now) && CurrentTargetAttackable(10.0, false, false))) && ((SpellManager.HasSpell("Roiling Blood") && THSettings.Instance.NecroticStrikeStack) && ((MyAuraTimeLeft("Frost Fever", Me.CurrentTarget) > 8000.0) && (MyAuraTimeLeft("Blood Plague", Me.CurrentTarget) > 8000.0)))) && (((Me.BloodRuneCount > 0) && (Me.FrostRuneCount == 0)) && CanCastCheck("Blood Boil", false))) && !HasEnemyNearGotCCBreakonDamge(Me.CurrentTarget, (float)(10 + GlyphprivateofPestilenceBonus)), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Blood Boil", Me.CurrentTarget, "BloodBoilRoilingBloodConversion");
                LastSpreadDiseases = DateTime.Now + TimeSpan.FromMilliseconds(2000.0);
            }));
        }
        #endregion

        #region BloodStrikeConversion@
        private static Composite BloodStrikeConversion()
        {
            return new Decorator(ret => (((CurrentTargetAttackable(5.0, false, false) && FacingOverride(Me.CurrentTarget)) && (THSettings.Instance.NecroticStrikeStack && (Me.BloodRuneCount > 0))) && (Me.FrostRuneCount == 0)) && CanCastCheck("Blood Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Blood Strike", Me.CurrentTarget, "BloodStrikeConversion");
            }));
        }
        #endregion

        #region BloodBoilRoilingBloodDumbRune@

        //private static Composite BloodBoilRoilingBloodDumbRune()
        //{
        //    return new Decorator(
        //        ret =>
        //        THSettings.Instance.BloodBoil &&
        //        //Only Use this Spell in PvP
        //        THSettings.Instance.NecroticStrikeDebuff &&
        //        THSettings.Instance.NecroticStrikeStack &&
        //        LastSpreadDiseases + TimeSpan.FromMilliseconds(2000) < DateTime.Now &&
        //        //!Casting() &&
        //        SpellManager.HasSpell("Blood Boil") &&
        //        SpellManager.HasSpell("Roiling Blood") &&
        //        !NecroticStrikeAvailable() &&
        //        //GetBestBloodBoilRoilingBloodTarget() &&
        //        //BestBloodBoilRoilingBloodTarget != null &&
        //        //BestBloodBoilRoilingBloodTarget.IsValid &&
        //        //CountEnemyNearNoCCBreakonDamge(BestBloodBoilRoilingBloodTarget, 10) <= 0 &&
        //        ////CountEnemyDontHaveBloodPlagueorFrostFever() > 0 &&
        //        //CanCastCheck("Blood Boil", BestBloodBoilRoilingBloodTarget, true),
        //        CurrentTargetAttackable(10) &&
        //        MyAuraTimeLeft("Frost Fever", Me.CurrentTarget) > 8000 &&
        //        MyAuraTimeLeft("Blood Plague", Me.CurrentTarget) > 8000 &&
        //        CountEnemyNearNoCCBreakonDamge(Me.CurrentTarget, 10) <= 0 &&
        //        CanCastCheck("Blood Boil"),
        //        new Action(delegate
        //            {
        //                LastSpreadDiseases = DateTime.Now;
        //                CastSpell("Blood Boil", Me.CurrentTarget, "BloodBoilRoilingBloodDumbRune");
        //            }));
        //}

        #endregion

        #region BloodBoilUnholyAoE@

        private static Composite BloodBoilUnholyAoE()
        {
            return new Decorator(ret => (THSettings.Instance.BloodBoil && CurrentTargetAttackable(10.0, false, false)) && CanCastCheck("Blood Boil", false), new Styx.TreeSharp.Action(delegate(object ret)
            {
                CastSpell("Blood Boil", Me, "BloodBoilUnholyAoE");
            }));
        }

        #endregion

        #region BloodFury@

        private static Composite BloodFury()
        {
            return new PrioritySelector(new Composite[] { new Decorator(delegate (object ret) {
                if (((!THSettings.Instance.AutoRacial || !Me.Combat) || !CurrentTargetAttackable(5.0, false, false)) || (!MeHasAura(0xc847) && !MeHasAura(0xbf78)))
                {
                    return false;
                }
                return CanCastCheck("Blood Fury", true);
            }, new Styx.TreeSharp.Action(delegate (object ret) {
                CastSpell("Blood Fury", Me, "");
                return RunStatus.Failure;
            })), new Decorator(delegate (object ret) {
                if (((!THSettings.Instance.AutoRacial || !Me.Combat) || !CurrentTargetAttackable(5.0, false, false)) || (!MeHasAura(0xc847) && !MeHasAura(0xbf78)))
                {
                    return false;
                }
                return CanCastCheck("Berserking", true);
            }, new Styx.TreeSharp.Action(delegate (object ret) {
                CastSpell("Berserking", Me, "");
                return RunStatus.Failure;
            })) });
        }

        #endregion

        #region BloodStrike@

        private static Composite BloodStrike()
        {
            return new Decorator(ret => ((((UseSpecialization == 1) && !SpellManager.HasSpell("Heart Strike")) || ((UseSpecialization == 3) && !SpellManager.HasSpell("Festering Strike"))) && (CurrentTargetAttackable(5.0, false, false) && FacingOverride(Me.CurrentTarget))) && CanCastCheck("Blood Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Blood Strike", Me.CurrentTarget, "BloodStrike");
            }));
        }

        #endregion

        #region BloodTap@

        private static DateTime BloodTapLast;

        private static Composite BloodTap()
        {
            return new Decorator(delegate(object ret)
            {
                if ((((!THSettings.Instance.BloodTap || ((BloodTapLast + TimeSpan.FromMilliseconds(2000.0)) >= DateTime.Now)) || (!(LastCastSpell != "Blood Tap") || !Me.Combat)) || ((!CurrentTargetAttackable(10.0, false, false) || !MeHasAura("Blood Charge")) || (MyTotalActiveRune() >= 6))) || ((((!Burst && !MeHasAura("Pillar of Frost")) && !MeHasAura("Unholy Frenzy")) || (MyAuraStackCount("Blood Charge", Me) < 5.0)) && (MyAuraStackCount("Blood Charge", Me) < THSettings.Instance.BloodChargeStack)))
                {
                    return false;
                }
                return CanCastCheck("Blood Tap", true);
            }, new Styx.TreeSharp.Action(delegate(object ret)
            {
                BloodTapLast = DateTime.Now;
                CastSpell("Blood Tap", Me, "");
                SpellsCooldownCache.Clear();
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region CalculateDropLocation@

        private static WoWPoint CalculateDropLocation(WoWUnit target)
        {
            if (!IsMoving(target) || target.MovementInfo.MovingBackward)
            {
                return target.Location;
            }
            return WoWMathHelper.CalculatePointBehind(target.Location, target.Rotation, -(5f + target.MovementInfo.RunSpeed));
        }

        #endregion

        #region CancelAura@

        private static void CancelAura(int HealthPercent)
        {
            WoWAura auraByName = Me.GetAuraByName("Conversion");
            if (((HealWeight(Me) >= HealthPercent) && (auraByName != null)) && auraByName.Cancellable)
            {
                auraByName.TryCancelAura();
            }
        }
        private static void CancelAura(string AuraName)
        {
            WoWAura auraByName = Me.GetAuraByName(AuraName);
            if ((auraByName != null) && auraByName.Cancellable)
            {
                auraByName.TryCancelAura();
            }
        }

        #endregion

        #region ChainsofIce@

        private static DateTime LastChainsofIce;

        private static Composite ChainsofIce()
        {
            return new Decorator(delegate(object ret)
            {
                //.if ((((!THSettings.Instance.ChainsofIce || ((LastGripSnare + TimeSpan.FromSeconds(2.0)) >= DateTime.Now)) || (!CurrentTargetAttackable(30.0, false, false) || (GetDistance(Me.CurrentTarget) <= 5f))) || ((InvulnerableSpell(Me.CurrentTarget) || InvulnerableRootandSnare(Me.CurrentTarget)) || DebuffRootorSnare(Me.CurrentTarget))) || (!CanUseDeathRune() && (Me.FrostRuneCount <= 0)))
                if ((((!THSettings.Instance.ChainsofIce || ((LastGripSnare + TimeSpan.FromSeconds(2.0)) >= DateTime.Now)) || (!CurrentTargetAttackable(30.0, false, false) || (GetDistance(Me.CurrentTarget) <= 5f))) || ((InvulnerableSpell(Me.CurrentTarget) || InvulnerableRootandSnare(Me.CurrentTarget)) || DebuffRootorSnare(Me.CurrentTarget))))
                {
                    return false;
                }
                return CanCastCheck("Chains of Ice", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastGripSnare = DateTime.Now;
                CastSpell("Chains of Ice", Me.CurrentTarget, "");
                LastChainsofIce = DateTime.Now;
            }));
        }

        #endregion

        #region ChainsofIceMelee@

        private static DateTime LastChainsofIceMelee;
        private static WoWUnit UnitChainsofIceMelee;

        private static bool GetUnitChainsofIceMelee()
        {
            UnitChainsofIceMelee = null;
            UnitChainsofIceMelee = (from unit in NearbyUnFriendlyPlayers.Where<WoWUnit>(new Func<WoWUnit, bool>(Classname.BasicCheck))
                                    orderby unit.CurrentHealth
                                    select unit).FirstOrDefault<WoWUnit>(unit => ((((Attackable(unit, 30) && (unit.CurrentTarget != null)) && (unit.CurrentTarget.IsValid && (unit.Class != WoWClass.Druid))) && (((unit.Class != WoWClass.Paladin) && (TalentSort(unit) == 1)) && (IsMoving(unit.CurrentTarget) && unit.GotTarget))) && (((FarFriendlyPlayers.Contains(unit.CurrentTarget) && (unit.CurrentTarget.HealthPercent < unit.HealthPercent)) && ((unit.CurrentTarget.HealthPercent <= THSettings.Instance.ChainofIceMeleeHP) && (unit.Location.Distance(unit.CurrentTarget.Location) < 10f))) && (!DebuffRootorSnare(unit) && !InvulnerableSpell(unit)))) && !InvulnerableRootandSnare(unit));
            return BasicCheck(UnitChainsofIceMelee);
        }

        private static Composite ChainsofIceMelee()
        {
            return new Decorator(ret => (((((THSettings.Instance.ChainofIceMelee && ((LastGripSnare + TimeSpan.FromSeconds(2.0)) < DateTime.Now)) && (((LastChainsofIceMelee + TimeSpan.FromSeconds(2.0)) < DateTime.Now) && Me.Combat)) && (InArena || InBattleground)) && (CanUseDeathRune() || (Me.FrostRuneCount > 0))) && CanCastCheck("Chains of Ice", false)) && GetUnitChainsofIceMelee(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastGripSnare = DateTime.Now;
                CastSpell("Chains of Ice", UnitChainsofIceMelee, "ChaisnofIceMelee");
                LastChainsofIceMelee = DateTime.Now;
            }));
        }

        #endregion

        #region ControlUndead@

        private static readonly HashSet<uint> CanControlUndead = new HashSet<uint>();

        private static WoWUnit UnitControlUndeadLast;
        private static WoWUnit UnitControlUndead;
        private static DateTime LastControlUndead;

        private static bool GetUnitControlUndead()
        {
            UnitControlUndead = null;
            UnitControlUndead = (from unit in NearbyUnFriendlyUnits.Where<WoWUnit>(new Func<WoWUnit, bool>(Classname.BasicCheck))
                                 orderby unit.MaxHealth descending, unit.HealthPercent descending
                                 select unit).FirstOrDefault<WoWUnit>(unit => ((((unit != null) && unit.IsValid) && ((unit.CreatureType == WoWCreatureType.Undead) && (unit != UnitControlUndeadLast))) && ((!CanControlUndead.Contains(unit.Entry) && !unit.IsBoss) && FacingOverride(unit))) && Attackable(unit, 30));
            return BasicCheck(UnitControlUndead);
        }

        private static DateTime CanControlUndeadLast;

        private static Composite ControlUndeadUpdate()
        {
            return new Decorator(ret => ((THSettings.Instance.ControlUndead && ((CanControlUndeadLast + TimeSpan.FromMinutes(1.0)) < DateTime.Now)) && Me.GotAlivePet) && !CanControlUndead.Contains(Me.Pet.Entry), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CanControlUndead.Add(Me.Pet.Entry);
                CanControlUndeadLast = DateTime.Now;
                return RunStatus.Failure;
            }));
        }

        private static Composite ControlUndead()
        {
            return new Decorator(ret => (((THSettings.Instance.ControlUndead && !Me.GotAlivePet) && (((LastControlUndead + TimeSpan.FromMilliseconds(10000.0)) < DateTime.Now) && !IsMoving(Me))) && CanCastCheck("Control Undead", false)) && GetUnitControlUndead(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastControlUndead = DateTime.Now;
                SafelyFacingTarget(UnitControlUndead);
                CastSpell("Control Undead", UnitControlUndead, "");
                UnitControlUndeadLast = UnitControlUndead;
            }));
        }

        #endregion

        #region Conversion@

        private static Composite Conversion()
        {
            return new PrioritySelector(new Composite[] { new Decorator(delegate (object ret) {
                if (((!THSettings.Instance.HealAttackC || MeHasAura("Conversion")) || ((PlayerRunicPower() < 5.0) || HoldSpendingRunicPower())) || ((Me.HealthPercent > THSettings.Instance.HealAttackCHP) && (Me.Combat || (Me.HealthPercent > 85.0))))
                {
                    return false;
                }
                return CanCastCheck("Conversion", false);
            }, new Styx.TreeSharp.Action(delegate (object param0) {
                CastSpell("Conversion", Me, "Conversion");
            })), new Decorator(delegate (object ret) {
                if ((((!THSettings.Instance.HealAttackC || !Me.Combat) || (!MeHasAura("Conversion") || (PlayerRunicPower() < 5.0))) || HoldSpendingRunicPower()) || (((Me.HealthPercent > (THSettings.Instance.HealAttackCHP - 20)) || CurrentTargetAttackable(5.0, false, false)) && (Me.HealthPercent > THSettings.Instance.UrgentHeal)))
                {
                    return false;
                }
                return CanCastCheck("Conversion", false);
            }, new Styx.TreeSharp.Action(delegate (object param0) {
                CancelAura("Conversion");
                CastSpell("Conversion", Me, "Double Conversion");
            })) });
        }

        #endregion

        #region DancingRuneWeapon@

        private static Composite DancingRuneWeapon()
        {
            return new Decorator(ret => ((((THSettings.Instance.DancingRuneWeapon && (HealWeight(Me) <= THSettings.Instance.DancingRuneWeaponHP)) && CurrentTargetAttackable(30.0, false, false)) && (((Me.CurrentTarget.CurrentHealth > (Me.CurrentHealth * 0.8)) || InProvingGrounds) || (IsDummy(Me.CurrentTarget) || Me.CurrentTarget.IsPlayer))) && FacingOverride(Me.CurrentTarget)) && CanCastCheck("Dancing Rune Weapon", true), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Dancing Rune Weapon", Me.CurrentTarget, "DancingRuneWeapon");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region DarkCommand@

        private static WoWUnit UnitDarkCommand;
        private static DateTime LastTaunt;

        private static bool GetUnitDarkCommand()
        {
            UnitDarkCommand = null;
            UnitDarkCommand = NearbyUnFriendlyUnits.Where<WoWUnit>(new Func<WoWUnit, bool>(Classname.BasicCheck)).FirstOrDefault<WoWUnit>(unit => ((Me.Combat && ((InDungeon || InRaid) || InProvingGrounds)) && (((unit.Combat && !unit.Fleeing) && ((unit.ThreatInfo.RawPercent < 100) && unit.GotTarget)) && ((FarFriendlyPlayers.Contains(unit.CurrentTarget) && !unit.IsTargetingMeOrPet) && (!UnitHasAura("Vengeance", unit.CurrentTarget) && !MyAura("Death Grip", unit))))) && Attackable(unit, 30));
            return BasicCheck(UnitDarkCommand);
        }

        private static Composite DarkCommand()
        {
            return new Decorator(ret => ((THSettings.Instance.AutoTaunt && ((LastTaunt + TimeSpan.FromSeconds(1.0)) < DateTime.Now)) && (Me.Combat && CanCastCheck("Dark Command", true))) && GetUnitDarkCommand(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Dark Command", UnitDarkCommand, "");
                LastTaunt = DateTime.Now;
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region DarkSimulacrum@

        private static WoWUnit UnitDarkSimulacrum;

        private static bool GetUnitDarkSimulacrum()
        {
            UnitDarkSimulacrum = null;
            if (InBattleground || InArena)
            {
                UnitDarkSimulacrum = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(delegate(WoWUnit unit)
                {
                    if ((((!BasicCheck(unit) || !Me.Combat) || (!FacingOverride(unit) || InvulnerableSpell(unit))) || (unit.PowerType != WoWPowerType.Mana)) || ((!THSettings.Instance.DarkSimulacrumonCast || !unit.IsCasting) && !THSettings.Instance.DarkSimulacrumonCooldown))
                    {
                        return false;
                    }
                    return Attackable(unit, 40);
                });
            }
            else
            {
                UnitDarkSimulacrum = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(delegate(WoWUnit unit)
                {
                    if (((!BasicCheck(unit) || !Me.Combat) || (!FacingOverride(unit) || (unit.PowerType != WoWPowerType.Mana))) || ((!THSettings.Instance.DarkSimulacrumonCast || !unit.IsCasting) && !THSettings.Instance.DarkSimulacrumonCooldown))
                    {
                        return false;
                    }
                    return Attackable(unit, 40);
                });
            }
            return BasicCheck(UnitDarkSimulacrum);
        }

        private static Composite DarkSimulacrum()
        {
            return new Decorator(ret => ((THSettings.Instance.DarkSimulacrumon && (THSettings.Instance.DarkSimulacrumonCast || THSettings.Instance.DarkSimulacrumonCooldown)) && (Me.Combat && CanCastCheck("Dark Simulacrum", true))) && GetUnitDarkSimulacrum(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                FacingDelay = DateTime.Now;
                if ((THSettings.Instance.AutoFace && ((FacingDelay + TimeSpan.FromMilliseconds(100.0)) > DateTime.Now)) && !Me.IsFacing(UnitDarkSimulacrum))
                {
                    Me.SetFacing(UnitDarkSimulacrum);
                }
                CastSpell("Dark Simulacrum", UnitDarkSimulacrum, "");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region DarkSimulacrumUse@

        private static Composite DarkSimulacrumUse()
        {
            return new PrioritySelector(new Composite[] { new Decorator(ret => ((THSettings.Instance.DarkSimulacrumonAuto && MeHasAura(0x12f30)) && (Me.CurrentPendingCursorSpell != null)) && !Me.HasPendingSpell("Death and Decay"), new Styx.TreeSharp.Action(delegate (object param0) {
                Logging.Write("DarkSimulacrumUse Click " + Me.CurrentPendingCursorSpell.Name);
                SpellManager.ClickRemoteLocation(Me.Location);
                return RunStatus.Failure;
            })), new Decorator(ret => (THSettings.Instance.DarkSimulacrumonAuto && CurrentTargetAttackable(30.0, false, false)) && MeHasAura(0x12f30), new Styx.TreeSharp.Action(delegate (object param0) {
                Logging.Write("DarkSimulacrumUse " + WoWSpell.FromId(0x12f26));
                SpellManager.Cast(0x12f26);
                return RunStatus.Failure;
            })) });
        }

        #endregion

        #region DarkSuccor 101568@

        private static Composite DarkSuccor()
        {
            return new Decorator(ret => (CurrentTargetAttackable(5.0, false, false) && MeHasAura(0x18cc0)) && FacingOverride(Me.CurrentTarget), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Death Strike", Me.CurrentTarget, "Dark Succor");
            }));
        }

        #endregion

        #region DarkTransformation@

        //private static DateTime SpamUntil;

        private static Composite DarkTransformation()
        {
            return new Decorator(ret => Me.GotAlivePet && MyAuraStackCount(91342, Me) >= 5 && CurrentTargetAttackable(30.0, false, false) && CanCastCheck("Dark Transformation", false), new Action(delegate
            {
                CastSpell("Dark Transformation", Me, "DarkTransformation");
            }));
        }

        #endregion

        #region DeathandDecay@

        //private  WoWUnit _unitDeathandDecay;

        //private  bool GetUnitDeathandDecay()
        //{
        //    _unitDeathandDecay = null;
        //    //using (StyxWoW.Memory.AcquireFrame())
        //    {
        //        _unitDeathandDecay = (from unit in NearbyUnFriendlyUnits
        //                              orderby CountEnemyNear(unit, 10) ascending
        //                              where Attackable(unit, 30)
        //                              select unit).FirstOrDefault();
        //    }
        //    return _unitDeathandDecay != null;
        //}

        private static Composite DeathandDecay()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.DeathandDecay || IsMoving(Me)) || !CurrentTargetAttackable(10.0, false, false)) || ((Me.CurrentTarget.CurrentHealth <= (Me.MaxHealth * 0.5)) && !IsDummy(Me.CurrentTarget)))
                {
                    return false;
                }
                return CanCastCheck("Death and Decay", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastCastontheGround = DateTime.Now;
                CastSpell("Death and Decay", Me, "DeathandDecay");
                new Wait(TimeSpan.FromMilliseconds(300.0), ret => Me.HasPendingSpell("Death and Decay"), new ActionAlwaysSucceed());
                LastCastontheGroundPosition = CalculateDropLocation(Me.CurrentTarget);
                SpellManager.ClickRemoteLocation(LastCastontheGroundPosition);
            }));
        }

        #endregion

        #region DeathandDecaySnare@

        private static DateTime LastCastontheGround;
        private static WoWPoint LastCastontheGroundPosition;
        private static DateTime LastGripSnare;

        private static Composite DeathandDecaySnare()
        {
            return new Decorator(ret => (((((THSettings.Instance.DeathandDecaySnare && (LastCastSpell != "Death Grip")) && (HasGlyph.Contains("58629") && ((LastGripSnare + TimeSpan.FromSeconds(2.0)) < DateTime.Now))) && (CurrentTargetAttackable(30.0, false, false) && (CanUseDeathRune() || (Me.UnholyRuneCount > 0)))) && ((((Me.CurrentTarget.IsPlayer && (TalentSort(Me.CurrentTarget) > 1)) && (Me.CurrentTarget.Distance >= THSettings.Instance.ChainsofIceMinDistance)) || ((Me.CurrentTarget.IsPlayer && (TalentSort(Me.CurrentTarget) == 1)) && ((Me.CurrentTarget.Distance >= THSettings.Instance.ChainsofIceMinDistance) && !Me.CurrentTarget.IsSafelyFacing(Me)))) || (((Me.CurrentTarget.IsPlayer && (TalentSort(Me.CurrentTarget) == 1)) && Me.CurrentTarget.IsSafelyBehind(Me)) || (Me.CurrentTarget.Fleeing && (Me.CurrentTarget.Distance >= THSettings.Instance.ChainsofIceMinDistance))))) && ((!InvulnerableSpell(Me.CurrentTarget) && !InvulnerableRootandSnare(Me.CurrentTarget)) && !DebuffRootorSnare(Me.CurrentTarget))) && CanCastCheck("Death and Decay", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastGripSnare = DateTime.Now;
                LastCastontheGround = DateTime.Now;
                CastSpell("Death and Decay", Me, "DeathandDecaySnare");
                new Wait(TimeSpan.FromMilliseconds(300.0), ret => Me.HasPendingSpell("Death and Decay"), new ActionAlwaysSucceed());
                LastCastontheGroundPosition = CalculateDropLocation(Me.CurrentTarget);
                SpellManager.ClickRemoteLocation(LastCastontheGroundPosition);
            }));
        }

        #endregion

        #region DeathandDecayTH@

        //private static Composite DeathandDecayTH()
        //{
        //    return new Decorator(
        //        ret =>
        //        THSettings.Instance.DeathandDecay &&
        //        SpellManager.HasSpell("Death and Decay") &&
        //        !InBattleground &&
        //        !InArena &&
        //        //!IsMoving(Me) &&
        //        //!Casting() &&
        //        CurrentTargetAttackable(10) &&
        //        (IsDummy(Me.CurrentTarget) ||
        //         Me.CurrentTarget.CurrentHealth > Me.MaxHealth*0.5) &&
        //        //(Me.UnholyRuneCount == 2 || CountEnemyNear(Me, 10) > 1) &&
        //        CanCastCheck("Death and Decay") &&
        //        (!SpellManager.HasSpell("Obliterate") ||
        //         SpellManager.HasSpell("Obliterate") &&
        //         !CanCastCheck("Obliterate") ||
        //         CountEnemyNear(Me, 10) > 1),
        //        new Action(
        //            ret =>
        //                {
        //                    LastCastontheGround = DateTime.Now;
        //                    CastSpell("Death and Decay", Me, "DeathandDecayTH");
        //                    while (LastCastontheGround + TimeSpan.FromMilliseconds(300) > DateTime.Now &&
        //                           Me.CurrentPendingCursorSpell == null)
        //                    {
        //                        Logging.Write("Waiting for Death and Decay CurrentPendingCursorSpell");
        //                    }
        //                    SpellManager.ClickRemoteLocation(Me.CurrentTarget.Location);
        //                })
        //        );
        //}

        #endregion

        #region DeathandDecayAoE@

        private static Composite DeathandDecayAoE()
        {
            return new Decorator(delegate(object ret)
            {
                if ((!THSettings.Instance.DeathandDecay || !CurrentTargetAttackable(10.0, false, false)) || ((Me.CurrentTarget.CurrentHealth <= (Me.MaxHealth * 0.5)) && !IsDummy(Me.CurrentTarget)))
                {
                    return false;
                }
                return CanCastCheck("Death and Decay", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastCastontheGround = DateTime.Now;
                CastSpell("Death and Decay", Me, "DeathandDecayAoE");
                new Wait(TimeSpan.FromMilliseconds(300.0), ret => Me.HasPendingSpell("Death and Decay"), new ActionAlwaysSucceed());
                SpellManager.ClickRemoteLocation(Me.CurrentTarget.Location);
            }));
        }

        #endregion

        #region DeathandDecayAoELow@

        //private static Composite DeathandDecayAoELow()
        //{
        //    return new Decorator(
        //        ret =>
        //        THSettings.Instance.DeathandDecay &&
        //        !IsMoving(Me) &&
        //        //!Casting() &&
        //        CurrentTargetAttackable(10) &&
        //        (Me.CurrentTarget.CurrentHealth > Me.MaxHealth*0.5 ||
        //         IsDummy(Me.CurrentTarget)) &&
        //        SpellManager.HasSpell("Death and Decay") &&
        //        CanCastCheck("Death and Decay"),
        //        new Action(
        //            ret =>
        //                {
        //                    LastCastontheGround = DateTime.Now;
        //                    CastSpell("Death and Decay", Me, "DeathandDecayAoELow");
        //                    while (LastCastontheGround + TimeSpan.FromMilliseconds(300) > DateTime.Now &&
        //                           Me.CurrentPendingCursorSpell == null)
        //                    {
        //                        Logging.Write("Waiting for Death and Decay CurrentPendingCursorSpell");
        //                    }
        //                    SpellManager.ClickRemoteLocation(Me.CurrentTarget.Location);
        //                })
        //        );
        //}

        #endregion

        #region DeathandDecayDW@

        private static Composite DeathandDecayDW()
        {
            return new Decorator(ret => (((THSettings.Instance.DeathandDecay && CurrentTargetAttackable(10.0, false, false)) && (IsDummy(Me.CurrentTarget) || (Me.CurrentTarget.CurrentHealth > (Me.MaxHealth * 0.5)))) && CanCastCheck("Death and Decay", false)) && ((!SpellManager.HasSpell("Obliterate") || (SpellManager.HasSpell("Obliterate") && !CanCastCheck("Obliterate", false))) || (CountEnemyNear(Me, 15f) > 1.0)), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastCastontheGround = DateTime.Now;
                CastSpell("Death and Decay", Me, "DeathandDecayDW");
                new Wait(TimeSpan.FromMilliseconds(300.0), ret => Me.HasPendingSpell("Death and Decay"), new ActionAlwaysSucceed());
                SpellManager.ClickRemoteLocation(Me.CurrentTarget.Location);
            }));
        }

        #endregion

        #region DeathCoil@

        //private static Composite DeathCoil()
        //{
        //    return new Decorator(
        //        ret =>
        //        THSettings.Instance.DeathCoil &&
        //        SpellManager.HasSpell("Death Coil") &&
        //        !Me.Mounted &&
        //        //!Casting() &&
        //        !HoldSpendingRunicPower() &&
        //        PlayerRunicPower >= 80 &&
        //        CurrentTargetAttackable(30) &&
        //        GetDistance(Me.CurrentTarget) > 5 &&
        //        !InvulnerableSpell(Me.CurrentTarget) &&
        //        FacingOverride(Me.CurrentTarget) &&
        //        CanCastCheck("Death Coil"),
        //        new Action(delegate
        //            {
        //                //Logging.Write(LogLevel.Diagnostic, "HowlingBlast");
        //                SafelyFacingTarget(Me.CurrentTarget);
        //                CastSpell("Death Coil", Me.CurrentTarget);
        //            }));
        //}

        #endregion

        #region DeathCoilSuddenDoom@

        private static Composite DeathCoilProc()
        {
            return new Decorator(ret => (((THSettings.Instance.DeathCoil && CurrentTargetAttackable(30.0, false, false)) && (((LastProc + TimeSpan.FromMilliseconds(1000.0)) < DateTime.Now) && MeHasAura(0x13dbc))) && (!InvulnerableSpell(Me.CurrentTarget) && FacingOverride(Me.CurrentTarget))) && CanCastCheck("Death Coil", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastProc = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Death Coil", Me.CurrentTarget, "DeathCoilProc");
            }));
        }

        #endregion

        #region DeathCoilCapRunicPower@

        private static DateTime LastCap;

        private static Composite DeathCoilCapRunicPower()
        {
            return new Decorator(ret => (((THSettings.Instance.DeathCoil && CurrentTargetAttackable(30.0, false, false)) && (((LastCap + TimeSpan.FromMilliseconds(1000.0)) < DateTime.Now) && (PlayerRunicPower() >= 80.0))) && (!InvulnerableSpell(Me.CurrentTarget) && FacingOverride(Me.CurrentTarget))) && CanCastCheck("Death Coil", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastCap = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Death Coil", Me.CurrentTarget, "DeathCoilCapRunicPower");
            }));
        }

        #endregion

        #region DeathCoilUnholy@

        private static Composite DeathCoilShadowInfusion()
        {
            return new Decorator(ret => (((THSettings.Instance.DeathCoil && CurrentTargetAttackable(30.0, false, false)) && (!HoldSpendingRunicPower() && FacingOverride(Me.CurrentTarget))) && ((!InvulnerableSpell(Me.CurrentTarget) && (MyAuraStackCount(0x164ce, Me) < 5.0)) && (Me.GotAlivePet && !UnitHasAura("Dark Transformation", Me.Pet)))) && CanCastCheck("Death Coil", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Death Coil", Me.CurrentTarget, "DeathCoilShadowInfusion");
            }));
        }

        #endregion

        #region DeathCoilHeal@

        private static Composite DeathCoilHeal()
        {
            return new Decorator(ret => ((THSettings.Instance.LichborneHeal && MeHasAura("Lichborne")) && (HealWeight(Me) <= THSettings.Instance.DoNotHealAbove)) && CanCastCheck("Death Coil", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Death Coil", Me, "DeathCoilHeal");
            }));
        }

        #endregion

        #region DeathCoilHealPet@

        private static DateTime DeathCoilHealPetLast;

        private static Composite DeathCoilHealPet()
        {
            return new Decorator(ret => (((((THSettings.Instance.DeathCoilHealPet && ((DeathCoilHealPetLast + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && (!MeHasAura("Preparation") && !MeHasAura("Arena Preparation"))) && (Me.GotAlivePet && (Me.Pet.Distance < 30.0))) && ((Me.Pet.HealthPercent <= THSettings.Instance.DeathCoilHealPetHP) || ((!UnitHasAura("Dark Transformation", Me.Pet) && !Me.Combat) && (MyAuraTimeLeft(0x164ce, Me) < 5000.0)))) && InLineOfSpellSightCheck(Me.Pet)) && CanCastCheck("Death Coil", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                DeathCoilHealPetLast = DateTime.Now;
                Lua.DoString("RunMacroText('/cast [@pet] Death Coil');", "WoW.lua");
                CastSpell("Death Coil", Me.Pet, "DeathCoilHealPet");
            }));
        }

        #endregion

        #region DeathPact@

        //private static DateTime LastDeathPact;

        private static Composite DeathPact()
        {
            return new PrioritySelector(new Composite[] { new Decorator(delegate (object ret) {
                if (((!THSettings.Instance.HealAttackD || !Me.Combat) || (HealWeight(Me) > THSettings.Instance.HealAttackDHP)) || ((Me.Minions.Count <= 0) && !Me.GotAlivePet))
                {
                    return false;
                }
                return CanCastCheck("Death Pact", false);
            }, new Styx.TreeSharp.Action(delegate (object param0) {
                CastSpell("Death Pact", Me, "");
            })), new Decorator(ret => (((THSettings.Instance.HealAttackD && Me.Combat) && ((HealWeight(Me) <= THSettings.Instance.HealAttackDHP) && (Me.Minions.Count == 0))) && (!Me.GotAlivePet && CanCastCheck("Death Pact", false))) && CanCastCheck("Raise Dead", false), new Styx.TreeSharp.Action(delegate (object param0) {
                CastSpell("Raise Dead", Me, "DeathPact - Raise Dead");
            })) });
        }

        #endregion

        #region DeathGrip@

        private static DateTime FacingDelay;

        private static Composite DeathGrip()
        {
            return new Decorator(ret => (((((THSettings.Instance.DeathGrip && (THSettings.Instance.DeathGripMinDistance > 0)) && (((LastGripSnare + TimeSpan.FromSeconds(2.0)) < DateTime.Now) && CurrentTargetAttackable(30.0, false, false))) && ((!InvulnerableSpell(Me.CurrentTarget) && !Me.CurrentTarget.IsBoss) && (Me.CurrentTarget.GotTarget && FacingOverride(Me.CurrentTarget)))) && ((!Me.CurrentTarget.Rooted && (Me.CurrentTarget.Distance >= THSettings.Instance.DeathGripMinDistance)) && (!IsMoving(Me.CurrentTarget) || !Me.CurrentTarget.IsSafelyFacing(Me)))) && (!Me.CurrentTarget.Buffs.ContainsKey("Ring of Peace") && (CanCastCheck("Death Grip", true)))) && !HasMeleeFriendDPSTarget(Me.CurrentTarget, 10.0), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastGripSnare = DateTime.Now;
                FacingDelay = DateTime.Now;
                if ((THSettings.Instance.AutoFace && ((FacingDelay + TimeSpan.FromMilliseconds(100.0)) > DateTime.Now)) && !Me.IsFacing(Me.CurrentTarget))
                {
                    Me.SetFacing(Me.CurrentTarget);
                }
                CastSpell("Death Grip", Me.CurrentTarget, "DeathGrip");
                LastTaunt = DateTime.Now;
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region DeathGripFarUnit@

        private static WoWUnit UnitDeathGripFarUnit;

        private static bool GetUnitDeathGripFarUnit()
        {
            UnitDeathGripFarUnit = null;
            UnitDeathGripFarUnit = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => (((((BasicCheck(unit) && unit.Combat) && (FacingOverride(unit) && unit.GotTarget)) && (!UnitHasAura("Vengeance", unit.CurrentTarget) || (unit.CurrentTarget == Me))) && (!IsMoving(unit) || !unit.IsSafelyFacing(Me))) && ((GetDistance(unit) > THSettings.Instance.DeathGripMinDistance) && !InvulnerableSpell(unit))) && Attackable(unit, 30));
            return BasicCheck(UnitDeathGripFarUnit);
        }

        private static Composite DeathGripFarUnit()
        {
            return new Decorator(ret => (((THSettings.Instance.DeathGrip && ((LastTaunt + TimeSpan.FromSeconds(1.0)) < DateTime.Now)) && (InDungeon || InRaid)) && (Me.Combat && (CanCastCheck("Death Grip", true)))) && GetUnitDeathGripFarUnit(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                FacingDelay = DateTime.Now;
                if ((THSettings.Instance.AutoFace && ((FacingDelay + TimeSpan.FromMilliseconds(100.0)) > DateTime.Now)) && !Me.IsFacing(UnitDeathGripFarUnit))
                {
                    Me.SetFacing(UnitDeathGripFarUnit);
                }
                CastSpell("Death Grip", UnitDeathGripFarUnit, "DeathGripFarUnit");
                LastTaunt = DateTime.Now;
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region DeathGripInterrupt@

        private static bool GetUnitDeathGripInterrupt()
        {
            UnitInterrupt = null;
            if (InBattleground || InArena)
            {
                UnitInterrupt = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && ((((GetDistance(unit) > 5f) && !InvulnerableSpell(unit)) && (FacingOverride(unit) && !DebuffRoot(unit))) && InterruptCheck(unit, (double)THSettings.Instance.StrangulateInterruptMs, true))) && Attackable(unit, 30));
            }
            else
            {
                UnitInterrupt = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => (((BasicCheck(unit) && unit.Combat) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && ((((GetDistance(unit) > 5f) && !InvulnerableSpell(unit)) && (!unit.Rooted && FacingOverride(unit))) && (FarFriendlyPlayers.Contains(unit.CurrentTarget) && InterruptCheck(unit, (double)THSettings.Instance.StrangulateInterruptMs, true)))) && Attackable(unit, 30));
            }
            return BasicCheck(UnitInterrupt);
        }

        private static void DeathGripInterruptVoid()
        {
            if (((THSettings.Instance.DeathGripInterrupt && ((LastInterrupt + TimeSpan.FromMilliseconds(1000.0)) < DateTime.Now)) && (Me.Combat && CanCastCheck("Death Grip", true))) && GetUnitDeathGripInterrupt())
            {
                if (Me.IsCasting)
                {
                    SpellManager.StopCasting();
                }
                FacingDelay = DateTime.Now;
                if ((THSettings.Instance.AutoFace && ((FacingDelay + TimeSpan.FromMilliseconds(100.0)) > DateTime.Now)) && !Me.IsFacing(UnitInterrupt))
                {
                    Me.SetFacing(UnitInterrupt);
                }
                //new Wait(TimeSpan.FromMilliseconds(2000.0), ret => !UnitInterrupt.IsCasting || (UnitInterrupt.IsCasting && (UnitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > (THSettings.Instance.DeathGripInterruptMs + MyLatency))), new ActionAlwaysSucceed());
                while (UnitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > THSettings.Instance.StrangulateInterruptMs)
                {
                    Styx.Common.Logging.Write("Waiting for Death Grip");
                }                
                if (UnitInterrupt.IsCasting)
                {
                    CastSpell("Death Grip", UnitInterrupt, "DeathGripInterrupt");
                    LastInterrupt = DateTime.Now;
                }
            }
        }

        #endregion

        #region DeathGripMelee@

        private static WoWUnit UnitDeathGripMelee;

        private static bool GetUnitDeathGripMelee()
        {
            UnitDeathGripMelee = null;
            UnitDeathGripMelee = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => ((((BasicCheck(unit) && unit.GotTarget) && (unit.CurrentTarget.IsPlayer && (unit.CurrentTarget.HealthPercent <= THSettings.Instance.DeathGripMeleeHP))) && ((FarFriendlyPlayers.Contains(unit.CurrentTarget) && !InvulnerableSpell(unit)) && (!InvulnerableSpell(unit) && (HealWeight(Me) > THSettings.Instance.PriorityHeal)))) && ((((HealWeight(Me) > (unit.CurrentTarget.HealthPercent + 10.0)) && (TalentSort(unit) == 1)) && ((GetDistance(unit) > 10f) && !DebuffCC(unit))) && FacingOverride(unit))) && Attackable(unit, 30));
            return BasicCheck(UnitDeathGripMelee);
        }

        private static WoWUnit UnitAsphyxiateHelpFriend;

        private static bool GetUnitAsphyxiateHelpFriend()
        {
            UnitAsphyxiateHelpFriend = null;
            UnitAsphyxiateHelpFriend = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => (((BasicCheck(unit) && unit.GotTarget) && (unit.CurrentTarget.IsPlayer && FarFriendlyPlayers.Contains(unit.CurrentTarget))) && (((unit.CurrentTarget.HealthPercent <= THSettings.Instance.AsphyxiateHelpFriendHP) && !InvulnerableStun(unit)) && !DebuffCC(unit))) && Attackable(unit, 30));
            return BasicCheck(UnitAsphyxiateHelpFriend);
        }

        private static Composite DeathGripAsphyxiateHelpFriend()
        {
            return new PrioritySelector(new Composite[] { new Decorator(ret => ((((THSettings.Instance.DeathGripMelee && ((LastGripSnare + TimeSpan.FromSeconds(2.0)) < DateTime.Now)) && Me.Combat) && (InArena || InBattleground)) && (CanCastCheck("Death Grip", true))) && GetUnitDeathGripMelee(), new Styx.TreeSharp.Action(delegate (object param0) {
                LastGripSnare = DateTime.Now;
                FacingDelay = DateTime.Now;
                if ((THSettings.Instance.AutoFace && ((FacingDelay + TimeSpan.FromMilliseconds(100.0)) > DateTime.Now)) && !Me.IsFacing(UnitDeathGripMelee))
                {
                    Me.SetFacing(UnitDeathGripMelee);
                }
                CastSpell("Death Grip", UnitDeathGripMelee, "DeathGripMelee");
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.AsphyxiateHelpFriend && Me.Combat) && (InArena || InBattleground)) && CanCastCheck("Asphyxiate", true)) && GetUnitAsphyxiateHelpFriend()), new Styx.TreeSharp.Action(delegate (object param0) {
                LastGripSnare = DateTime.Now;
                FacingDelay = DateTime.Now;
                if ((THSettings.Instance.AutoFace && ((FacingDelay + TimeSpan.FromMilliseconds(100.0)) > DateTime.Now)) && !Me.IsFacing(UnitAsphyxiateHelpFriend))
                {
                    Me.SetFacing(UnitAsphyxiateHelpFriend);
                }
                CastSpell("Asphyxiate", UnitAsphyxiateHelpFriend, "Asphyxiate Help Friend");
                return RunStatus.Failure;
            })) });
        }

        #endregion

        #region DeathGripRemorselessWinter@

        private static WoWUnit UnitDeathGripRemorselessWinter;

        private static bool GetUnitDeathGripRemorselessWinter()
        {
            UnitDeathGripRemorselessWinter = null;
            UnitDeathGripRemorselessWinter = (from unit in NearbyUnFriendlyPlayers.Where<WoWUnit>(new Func<WoWUnit, bool>(Classname.BasicCheck))
                                              orderby MyAuraStackCount("Remorseless Winter", unit) descending
                                              select unit).FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && (unit.Distance > 8.0)) && (!DebuffCC(unit) && !DebuffRoot(unit))) && FacingOverride(unit));
            return BasicCheck(UnitDeathGripRemorselessWinter);
        }

        private static Composite DeathGripRemorselessWinter()
        {
            return new Decorator(ret => (((THSettings.Instance.RemorselessWinterDeathGrip && Me.Combat) && (InArena || InBattleground)) && (MeHasAura("Remorseless Winter") && (CanCastCheck("Death Grip", true)))) && GetUnitDeathGripRemorselessWinter(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                FacingDelay = DateTime.Now;
                if ((THSettings.Instance.AutoFace && ((FacingDelay + TimeSpan.FromMilliseconds(100.0)) > DateTime.Now)) && !Me.IsFacing(UnitDeathGripRemorselessWinter))
                {
                    Me.SetFacing(UnitDeathGripRemorselessWinter);
                }
                CastSpell("Death Grip", UnitDeathGripRemorselessWinter, "DeathGripRemorselessWinter");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region DeathGripTaunt@

        private static WoWUnit UnitDeathGripTaunt;

        private static bool GetUnitDeathGripTaunt()
        {
            UnitDeathGripTaunt = null;
            UnitDeathGripTaunt = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => ((((BasicCheck(unit) && unit.Combat) && (!unit.Fleeing && (unit.ThreatInfo.RawPercent < 100))) && ((unit.GotTarget && FarFriendlyPlayers.Contains(unit.CurrentTarget)) && (!unit.IsTargetingMeOrPet && !MyAura("Dark Command", unit)))) && !UnitHasAura("Vengeance", unit.CurrentTarget)) && FacingOverride(unit));
            return BasicCheck(UnitDeathGripTaunt);
        }

        private static Composite DeathGripTaunt()
        {
            return new Decorator(ret => ((THSettings.Instance.AutoTaunt && Me.Combat) && (((LastTaunt + TimeSpan.FromSeconds(1.0)) < DateTime.Now) && CanCastCheck("Death Grip", true))) && GetUnitDeathGripTaunt(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                FacingDelay = DateTime.Now;
                if ((THSettings.Instance.AutoFace && ((FacingDelay + TimeSpan.FromMilliseconds(100.0)) > DateTime.Now)) && !Me.IsFacing(UnitDeathGripTaunt))
                {
                    Me.SetFacing(UnitDeathGripTaunt);
                }
                CastSpell("Death Grip", UnitDeathGripTaunt, "DeathGripTaunt");
                LastTaunt = DateTime.Now;
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region Death's Advance@

        private static Composite DeathsAdvance()
        {
            return new Decorator(ret => ((THSettings.Instance.DeathsAdvance && CurrentTargetAttackable(30.0, false, false)) && ((GetDistance(Me.CurrentTarget) > 5f) && DebuffRoot(Me))) && CanCastCheck("Death's Advance", true), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Death's Advance", Me, "");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region DeathSiphon@

        private static Composite DeathSiphon()
        {
            return new Decorator(ret => (((THSettings.Instance.HealAttackS && Me.Combat) && ((HealWeight(Me) <= THSettings.Instance.HealAttackSHP) && CurrentTargetAttackable(30.0, false, false))) && FacingOverride(Me.CurrentTarget)) && CanCastCheck("Death Siphon", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Death Siphon", Me.CurrentTarget, "");
            }));
        }

        #endregion

        #region DeathStrikeUrgent@

        private static Composite DeathStrikeUrgent()
        {
            return new Decorator(ret => (((THSettings.Instance.DeathStrike && (HealWeight(Me) <= THSettings.Instance.DeathStrikeHP) && !HasHealerWithMe() && CountDPSTarget(Me) >= 1) && (CanUseDeathRune() || ((Me.FrostRuneCount > 0) && (Me.UnholyRuneCount > 0)))) && ((CurrentTargetAttackable(5.0, false, false) && (Me.CurrentTarget.CurrentHealth > Me.CurrentHealth)) && FacingOverride(Me.CurrentTarget))) && CanCastCheck("Death Strike", false), new Styx.TreeSharp.Action(delegate(object ret)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Death Strike", Me.CurrentTarget, "");
            }));
        }

        #endregion

        #region DeathStrike@

        private static Composite DeathStrike()
        {
            return new Decorator(ret => (((THSettings.Instance.DeathStrike && (HealWeight(Me) <= THSettings.Instance.DeathStrikeHP)) && (CanUseDeathRune() || ((Me.FrostRuneCount > 0) && (Me.UnholyRuneCount > 0)))) && ((CurrentTargetAttackable(5.0, false, false) && (Me.CurrentTarget.CurrentHealth > Me.CurrentHealth)) && FacingOverride(Me.CurrentTarget))) && CanCastCheck("Death Strike", false), new Styx.TreeSharp.Action(delegate(object ret)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Death Strike", Me.CurrentTarget, "");
            }));
        }

        #endregion

        #region DeathStrikeBlood@

        private static Composite DeathStrikeBlood()
        {
            return new Decorator(ret => ((THSettings.Instance.DeathStrikeBloodEnable && (CanUseDeathRune() || (Me.BloodRuneCount > 0))) && (CurrentTargetAttackable(5.0, false, false) && FacingOverride(Me.CurrentTarget))) && CanCastCheck("Death Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Death Strike", Me.CurrentTarget, "DeathStrikeBlood");
            }));
        }

        #endregion

        #region DeathStrikeBloodPvP@

        private static WoWUnit UnitDeathStrikeBloodPvP;

        private static bool GetUnitDeathStrikeBloodPvP()
        {
            UnitDeathStrikeBloodPvP = null;
            UnitDeathStrikeBloodPvP = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && !unit.IsPlayer) && (GetDistance(unit) <= 5f)) && FacingOverride(unit));
            return BasicCheck(UnitDeathStrikeBloodPvP);
        }

        private static Composite DeathStrikeBloodPvP()
        {
            return new Decorator(ret => (((THSettings.Instance.DeathStrikeBloodEnable && (InBattleground || InArena)) && (CanUseDeathRune() || ((Me.UnholyRuneCount > 0) && (Me.FrostRuneCount > 0)))) && ((HealWeight(Me) <= THSettings.Instance.BloodPresenceHP) && CanCastCheck("Death Strike", false))) && GetUnitDeathStrikeBloodPvP(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Death Strike", UnitDeathStrikeBloodPvP, "DeathStrikeBloodPvP");
            }));
        }

        #endregion

        #region DeathStrikeBloodShield@

        private static Composite DeathStrikeBloodShield()
        {
            return new Decorator(ret => (((THSettings.Instance.DeathStrikeBloodEnable && InRaid) && (CurrentTargetAttackable(5.0, false, false) && FacingOverride(Me.CurrentTarget))) && (MyAuraTimeLeft("Blood Shield", Me) < 2000.0)) && CanCastCheck("Death Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Death Strike", Me.CurrentTarget, "DeathStrikeBloodShield");
            }));
        }

        #endregion

        #region DeathCoilBloodFrost
        private static Composite DeathCoilBloodFrost()
        {
            return new Decorator(ret => (((THSettings.Instance.DeathCoil && CurrentTargetAttackable(30.0, false, false)) && (!HoldSpendingRunicPower() && (PlayerRunicPower() >= 80.0))) && (((GetDistance(Me.CurrentTarget) > 5f) && !InvulnerableSpell(Me.CurrentTarget)) && FacingOverride(Me.CurrentTarget))) && CanCastCheck("Death Coil", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Death Coil", Me.CurrentTarget, "DeathCoilBloodFrost");
            }));
        }
        #endregion

        #region DesecratedGround@

        private static DateTime BreakCCLast;

        private static Composite DesecratedGround()
        {
            return new Decorator(ret => ((THSettings.Instance.DesecratedGround && ((BreakCCLast + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && (DebuffCCDuration(Me, (double)THSettings.Instance.DesecratedGroundDebuffMinDuration, false) && !MeHasAura("Sap"))) && CanCastCheck("Desecrated Ground", true), new Styx.TreeSharp.Action(delegate(object param0)
            {
                BreakCCLast = DateTime.Now;
                CastSpell("Desecrated Ground", Me, "DesecratedGround");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region DeathCoilUnholy@
        private static Composite DeathCoilUnholy()
        {
            return new Decorator(ret => (((THSettings.Instance.DeathCoil && CurrentTargetAttackable(30.0, false, false)) && (!HoldSpendingRunicPower() && !InvulnerableSpell(Me.CurrentTarget))) && FacingOverride(Me.CurrentTarget)) && CanCastCheck("Death Coil", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Death Coil", Me.CurrentTarget, "DeathCoilUnholy");
            }));
        }
        #endregion

        #region EmpowerRuneWeapon@

        private static int MyTotalActiveRune()
        {
            return (((Me.BloodRuneCount + Me.FrostRuneCount) + Me.UnholyRuneCount) + Me.DeathRuneCount);
        }

        private static Composite EmpowerRuneWeapon()
        {
            //return new Decorator(ret => (((CurrentTargetAttackable(5.0, false, false) && ((Me.CurrentTarget.CurrentHealth > (Me.CurrentHealth * 0.8)) || IsDummy(Me.CurrentTarget))) && ((((THSettings.Instance.EmpowerRuneWeapon == 1) || ((THSettings.Instance.EmpowerRuneWeapon == 2) && Me.CurrentTarget.IsBoss)) || ((THSettings.Instance.EmpowerRuneWeapon == 3) && Burst)) || ((THSettings.Instance.EmpowerRuneWeapon == 4) && (Me.CurrentTarget.HealthPercent <= THSettings.Instance.EmpowerRuneWeaponPercent)))) && ((MyTotalActiveRune() < 1) && (PlayerRunicPower < 70.0))) && CanCastCheck("Empower Rune Weapon", true), new Styx.TreeSharp.Action(delegate(object param0)
            return new Decorator(ret => (((CurrentTargetAttackable(5.0, false, false) && (InArena || InBattleground || (Me.CurrentTarget.CurrentHealth > (Me.CurrentHealth * 0.8)) || IsDummy(Me.CurrentTarget))) && ((((THSettings.Instance.EmpowerRuneWeapon == 1) || ((THSettings.Instance.EmpowerRuneWeapon == 2) && Me.CurrentTarget.IsBoss)) || ((THSettings.Instance.EmpowerRuneWeapon == 3) && Burst)) || ((THSettings.Instance.EmpowerRuneWeapon == 4) && (Me.CurrentTarget.HealthPercent <= THSettings.Instance.EmpowerRuneWeaponPercent)))) && ((MyTotalActiveRune() < 1) && (PlayerRunicPower() < 70.0))) && CanCastCheck("Empower Rune Weapon", true), new Styx.TreeSharp.Action(delegate(object param0)            
            {
                CastSpell("Empower Rune Weapon", Me, "Empower Rune Weapon");
                SpellsCooldownCache.Clear();
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region FacingTarget@

        //private static Composite FacingTarget()
        //{
        //    return new Decorator(
        //        ret =>
        //        THSettings.Instance.AutoFace &&
        //        Me.Combat &&
        //        !Me.Mounted &&
        //        !IsOverrideModeOn &&
        //        !CurrentTargetCheckFacing &&
        //        CurrentTargetAttackable(10) &&
        //        (Me.CurrentTarget.IsTargetingMeOrPet ||
        //         Me.CurrentTarget.IsTargetingMyPartyMember ||
        //         Me.CurrentTarget.IsTargetingMyRaidMember),
        //        new Action(delegate
        //            {
        //                Me.SetFacing(Me.CurrentTarget);
        //                return RunStatus.Failure;
        //            })
        //        );
        //}

        #endregion

        #region FesteringStrike@

        private static Composite FesteringStrike()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.FesteringStrike || !CurrentTargetAttackable(5.0, false, false)) || !FacingOverride(Me.CurrentTarget)) || (!CanUseDeathRune() && ((Me.BloodRuneCount <= 0) || (Me.FrostRuneCount <= 0))))
                {
                    return false;
                }
                return CanCastCheck("Festering Strike", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Festering Strike", Me.CurrentTarget, "FesteringStrike");
            }));
        }

        #endregion

        #region FesteringStrike90@

        private static Composite FesteringStrike90()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.FesteringStrike || !CurrentTargetAttackable(5.0, false, false)) || ((PlayerRunicPower() >= 90.0) || !FacingOverride(Me.CurrentTarget))) || (!CanUseDeathRune() && ((Me.BloodRuneCount <= 0) || (Me.FrostRuneCount <= 0))))
                {
                    return false;
                }
                return CanCastCheck("Festering Strike", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Festering Strike", Me.CurrentTarget, "FesteringStrike90");
            }));
        }

        #endregion

        #region FesteringStrikeKeepDiseases@

        private static Composite FesteringStrikeKeepDiseases()
        {
            return new Decorator(ret => (((THSettings.Instance.FesteringStrike && CurrentTargetAttackable(5.0, false, false)) && ((MyAura("Frost Fever", Me.CurrentTarget) && (MyAuraTimeLeft("Frost Fever", Me.CurrentTarget) < 3000.0)) || (MyAura("Blood Plague", Me.CurrentTarget) && (MyAuraTimeLeft("Blood Plague", Me.CurrentTarget) < 3000.0)))) && (FacingOverride(Me.CurrentTarget) && (CanUseDeathRune() || ((Me.BloodRuneCount > 0) && (Me.FrostRuneCount > 0))))) && CanCastCheck("Festering Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Festering Strike", Me.CurrentTarget, "FesteringStrikeKeepDiseases");
            }));
        }

        #endregion

        #region FrostPresence@

        private static Composite FrostPresenceSwap()
        {
            return new Decorator(delegate(object ret)
            {
                if ((((!THSettings.Instance.AutoPrecence || ((PresenceSwapLast + TimeSpan.FromMilliseconds((double)THSettings.Instance.PresenceSwapTimeout)) >= DateTime.Now)) || (MeHasAura("Frost Presence") || MeHasAura("Alliance Flag"))) || ((MeHasAura("Horde Flag") || MeHasAura("Netherstorm Flag")) || MeHasAura("Orb of Power"))) || ((HealWeight(Me) <= THSettings.Instance.BloodPresenceHP) && !Burst))
                {
                    return false;
                }
                return CanCastCheck("Frost Presence", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                PresenceSwapLast = DateTime.Now;
                CastSpell("Frost Presence", Me, "FrostPresence");
            }));
        }

        #endregion

        #region FrostStrikeDWCap@

        //No dps increase = removed
        //private  DateTime FrostStrikeCostCheckLast;

        //private static Composite FrostStrikeCostUpdate()
        //{
        //    return new Decorator(
        //        ret =>
        //        FrostStrikeCostCheckLast + TimeSpan.FromSeconds(10) < DateTime.Now,
        //        new Action(delegate
        //                       {
        //                           FrostStrikeCostCheckLast = DateTime.Now;
        //                           if (SpellManager.HasSpell("Improved Frost Presence") && Me.HasAura("Frost Presence"))
        //                           {
        //                               FrostStrikeCost = 20;
        //                           }
        //                           else
        //                           {
        //                               FrostStrikeCost = 35;
        //                           }
        //                           return RunStatus.Failure;
        //                       }));
        //}

        #endregion

        #region FrostStrikeAoECap@

        private static Composite FrostStrikeAoECap()
        {
            return new Decorator(ret => (((THSettings.Instance.FrostStrike && ((LastCap + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && ((PlayerRunicPower() > 70.0) && CurrentTargetAttackable(5.0, false, false))) && FacingOverride(Me.CurrentTarget)) && CanCastCheck("Frost Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastCap = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Frost Strike", Me.CurrentTarget, "FrostStrikeAoECap");
            }));
        }

        #endregion

        #region FrostStrikeAoELow@

        private static Composite FrostStrikeAoELow()
        {
            return new Decorator(ret => ((THSettings.Instance.FrostStrike && CurrentTargetAttackable(5.0, false, false)) && FacingOverride(Me.CurrentTarget)) && CanCastCheck("Frost Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Frost Strike", Me.CurrentTarget, "FrostStrikeAoELow");
            }));
        }

        #endregion

        #region FrostStrikeTH@

        private static Composite FrostStrikeTH()
        {
            return new Decorator(ret => ((THSettings.Instance.FrostStrike && !HoldSpendingRunicPower()) && (CurrentTargetAttackable(5.0, false, false) && FacingOverride(Me.CurrentTarget))) && CanCastCheck("Frost Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Frost Strike", Me.CurrentTarget, "FrostStrikeTH");
            }));
        }

        #endregion

        #region FrostStrikeTHCap@

        private static Composite FrostStrikeTHCap()
        {
            return new Decorator(ret => (((THSettings.Instance.FrostStrike && ((LastCap + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && ((PlayerRunicPower() > 70.0) && CurrentTargetAttackable(5.0, false, false))) && FacingOverride(Me.CurrentTarget)) && CanCastCheck("Frost Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastCap = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Frost Strike", Me.CurrentTarget, "FrostStrikeTHCap");
            }));
        }

        #endregion

        #region FrostStrikeDW@

        private static Composite FrostStrikeDW()
        {
            return new Decorator(ret => (((THSettings.Instance.FrostStrike && !HoldSpendingRunicPower()) && (CurrentTargetAttackable(5.0, false, false) && (PlayerRunicPower() >= 60.0))) && FacingOverride(Me.CurrentTarget)) && CanCastCheck("Frost Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Frost Strike", Me.CurrentTarget, "FrostStrikeDW");
            }));
        }

        #endregion

        #region FrostStrikeDWKM@

        private static Composite FrostStrikeDWKM()
        {
            return new Decorator(ret => (((THSettings.Instance.FrostStrike && MeHasAura(0xc7b4)) && (!HoldSpendingRunicPower() && CurrentTargetAttackable(5.0, false, false))) && FacingOverride(Me.CurrentTarget)) && CanCastCheck("Frost Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Frost Strike", Me.CurrentTarget, "FrostStrikeDWKM");
            }));
        }

        #endregion

        #region FrostStrikeDWCap@

        private static Composite FrostStrikeDWCap()
        {
            return new Decorator(ret => (((THSettings.Instance.FrostStrike && ((LastCap + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && ((PlayerRunicPower() >= 70.0) && !HoldSpendingRunicPower())) && (CurrentTargetAttackable(5.0, false, false) && FacingOverride(Me.CurrentTarget))) && CanCastCheck("Frost Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastCap = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Frost Strike", Me.CurrentTarget, "FrostStrikeDWCap");
            }));
        }

        #endregion

        #region GargoyleFrenzy@

        private static Composite GargoyleFrenzy()
        {
            return new PrioritySelector(new Composite[] { new Decorator(delegate (object ret) {
                if (!CurrentTargetAttackable(30.0, false, false) || ((((THSettings.Instance.GargoyleFrenzy != 1) && ((THSettings.Instance.GargoyleFrenzy != 2) || !Me.CurrentTarget.IsBoss)) && ((THSettings.Instance.GargoyleFrenzy != 3) || !Burst)) && ((THSettings.Instance.GargoyleFrenzy != 4) || (Me.CurrentTarget.HealthPercent > THSettings.Instance.GargoyleFrenzyPercent))))
                {
                    return false;
                }
                return CanCastCheck("Summon Gargoyle", false);
            }, new Styx.TreeSharp.Action(delegate (object param0) {
                if (CanCastCheck("Unholy Frenzy", false))
                {
                    CastSpell("Unholy Frenzy", Me, "GargoyleFrenzy: Unholy Frenzy");
                }
                CastSpell("Summon Gargoyle", Me.CurrentTarget, "GargoyleFrenzy: Summon Gargoyle");
            })) });
        }

        #endregion

        #region GorefiendsGraspInterrupt@

        private static bool GetUnitGorefiendsGraspInterrupt()
        {
            UnitInterrupt = null;
            if (InBattleground || InArena)
            {
                UnitInterrupt = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && (((GetDistance(unit) > 5f) && !InvulnerableSpell(unit)) && (!unit.Rooted && InterruptCheck(unit, (double)THSettings.Instance.GorefiendsGraspInterruptMS, true)))) && Attackable(unit, 20));
            }
            else
            {
                UnitInterrupt = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && ((((unit.Distance <= 20.0) && (GetDistance(unit) > 5f)) && (FarFriendlyPlayers.Contains(unit.CurrentTarget) && !unit.Rooted)) && InterruptCheck(unit, (double)THSettings.Instance.GorefiendsGraspInterruptMS, true))) && Attackable(unit, 20));
            }
            return BasicCheck(UnitInterrupt);
        }

        private static void GorefiendsGraspInterruptVoid()
        {
            if (THSettings.Instance.GorefiendsGraspInterrupt &&
                LastInterrupt + TimeSpan.FromMilliseconds(1000) < DateTime.Now &&
                Me.Combat &&
                CanCastCheck("Gorefiend's Grasp", true) &&
                GetUnitGorefiendsGraspInterrupt())
            {
                if (Me.IsCasting)
                {
                    SpellManager.StopCasting();
                }
                //new Wait(TimeSpan.FromMilliseconds(2000.0), ret => !UnitInterrupt.IsCasting || (UnitInterrupt.IsCasting && (UnitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > (THSettings.Instance.GorefiendsGraspInterruptMS + MyLatency))), new ActionAlwaysSucceed());
                while (UnitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > THSettings.Instance.GorefiendsGraspInterruptMS)
                {
                    Styx.Common.Logging.Write("Waiting for Gorefiend's Grasp");
                }
                if (UnitInterrupt.IsCasting)
                {
                    CastSpell("Gorefiend's Grasp", Me, "GorefiendsGraspInterruptVoid");
                    LastInterrupt = DateTime.Now;
                }
            }
        }

        #endregion

        #region GorefiendsGraspAggro@

        private static WoWUnit UnitGorefiendsGraspAggro;

        private static bool GetUnitGorefiendsGraspAggro()
        {
            UnitGorefiendsGraspAggro = null;
            UnitGorefiendsGraspAggro = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => ((((BasicCheck(unit) && unit.Combat) && (unit.GotTarget && FarFriendlyPlayers.Contains(unit.CurrentTarget))) && (!IsTank(unit.CurrentTarget) && (!IsMoving(unit) || !unit.IsSafelyFacing(Me)))) && ((unit.Distance > THSettings.Instance.GorefiendsGraspAggroMinDist) && !InvulnerableSpell(unit))) && Attackable(unit, 20));
            return BasicCheck(UnitGorefiendsGraspAggro);
        }

        private static Composite GorefiendsGraspAggro()
        {
            return new Decorator(ret => (((THSettings.Instance.GorefiendsGraspAggro && ((LastTaunt + TimeSpan.FromSeconds(1.0)) < DateTime.Now)) && (InDungeon || InRaid)) && (Me.Combat && CanCastCheck("Gorefiend's Grasp", true))) && GetUnitGorefiendsGraspAggro(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Gorefiend's Grasp", Me, "GorefiendsGraspAggro");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region GorefiendsGraspKiter@

        private static Composite GorefiendsGraspKiter()
        {
            return new Decorator(delegate(object ret)
            {
                if ((((!THSettings.Instance.GorefiendsGraspKiter || (THSettings.Instance.GorefiendsGraspKiterMinDist <= 0)) || (((LastGripSnare + TimeSpan.FromSeconds(2.0)) >= DateTime.Now) || !CurrentTargetAttackable(20.0, false, false))) || ((InvulnerableSpell(Me.CurrentTarget) || Me.CurrentTarget.IsBoss) || (DebuffRoot(Me.CurrentTarget) || (Me.CurrentTarget.Distance < THSettings.Instance.DeathGripMinDistance)))) || (IsMoving(Me.CurrentTarget) && Me.CurrentTarget.IsSafelyFacing(Me)))
                {
                    return false;
                }
                return CanCastCheck("Gorefiend's Grasp", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastGripSnare = DateTime.Now;
                CastSpell("Gorefiend's Grasp", Me, "GorefiendsGraspKiter");
            }));
        }

        #endregion

        #region GorefiendsGraspMelee@

        private static WoWUnit UnitGorefiendsGraspMelee;

        private static bool GetUnitGorefiendsGraspMelee()
        {
            UnitGorefiendsGraspMelee = null;
            UnitGorefiendsGraspMelee = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => ((((BasicCheck(unit) && (TalentSort(unit) == 1)) && (unit.GotTarget && (unit.CurrentTarget != Me))) && ((FarFriendlyPlayers.Contains(unit.CurrentTarget) && !InvulnerableSpell(unit)) && (!DebuffRoot(unit) && (unit.CurrentTarget.HealthPercent <= THSettings.Instance.GorefiendsGraspMeleeHP)))) && ((((HealWeight(Me) > THSettings.Instance.PriorityHeal) && (HealWeight(Me) > (unit.CurrentTarget.HealthPercent + 10.0))) && ((GetDistance(unit) > 10f) && (GetDistance(unit.CurrentTarget) > 10f))) && FacingOverride(unit))) && Attackable(unit, 20));
            return BasicCheck(UnitGorefiendsGraspMelee);
        }

        private static Composite GorefiendsGraspMelee()
        {
            return new Decorator(ret => ((((THSettings.Instance.GorefiendsGraspMelee && ((LastGripSnare + TimeSpan.FromSeconds(2.0)) < DateTime.Now)) && Me.Combat) && (InArena || InBattleground)) && CanCastCheck("Gorefiend's Grasp", false)) && GetUnitGorefiendsGraspMelee(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastGripSnare = DateTime.Now;
                CastSpell("Gorefiend's Grasp", Me, "GorefiendsGraspMelee");
            }));
        }

        #endregion

        #region GorefiendsGraspAoE@

        private static double CountEnemyNearGorefiendsGraspAoE(WoWUnit unitCenter, float distance, string spellType)
        {
            return
                NearbyUnFriendlyUnits.Where(
                    unit =>
                    unitCenter.Location.Distance(unit.Location) <= distance &&
                    !DebuffCC(unit) &&
                    !DebuffRoot(unit) &&
                    !unit.Debuffs.ContainsKey(spellType)).Aggregate
                    <WoWUnit, double>(0, (current, unit) => current + 1);
        }

        private static WoWUnit UnitGorefiendsGraspAoE;

        private static bool GetUnitGorefiendsGraspAoE()
        {
            UnitGorefiendsGraspAoE = null;
            UnitGorefiendsGraspAoE = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(delegate(WoWUnit unit)
            {
                if ((!BasicCheck(unit) || InvulnerableSpell(unit)) || ((!UnitHasAura("Solar Beam", unit) || (CountEnemyNearGorefiendsGraspAoE(unit, 20f, "Solar Beam") < THSettings.Instance.GorefiendsGraspAoENumber)) && (!UnitHasAura("Ring of Frost", unit) || (CountEnemyNearGorefiendsGraspAoE(unit, 20f, "Ring of Frost") < THSettings.Instance.GorefiendsGraspAoENumber))))
                {
                    return false;
                }
                return Attackable(unit, 30);
            });
            return BasicCheck(UnitGorefiendsGraspAoE);
        }

        private static Composite GorefiendsGraspAoE()
        {
            return new Decorator(ret => (((THSettings.Instance.GorefiendsGraspAoE && Me.Combat) && (InArena || InBattleground)) && CanCastCheck("Gorefiend's Grasp", false)) && GetUnitGorefiendsGraspAoE(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                FacingDelay = DateTime.Now;
                if ((THSettings.Instance.AutoFace && ((FacingDelay + TimeSpan.FromMilliseconds(100.0)) > DateTime.Now)) && !Me.IsFacing(UnitGorefiendsGraspAoE))
                {
                    Me.SetFacing(UnitGorefiendsGraspAoE);
                }
                CastSpell("Gorefiend's Grasp", UnitGorefiendsGraspAoE, "GorefiendsGraspAoE");
            }));
        }

        #endregion

        #region HeartStrike@

        private static Composite HeartStrike()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.HeartStrike || !CurrentTargetAttackable(5.0, false, false)) || !FacingOverride(Me.CurrentTarget)) || (!CanUseDeathRune() && (Me.BloodRuneCount <= 0)))
                {
                    return false;
                }
                return CanCastCheck("Heart Strike", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Heart Strike", Me.CurrentTarget, "");
            }));
        }

        #endregion

        #region HeartStrikeAoE@

        private static Composite HeartStrikeAoE()
        {
            return new Decorator(ret => ((THSettings.Instance.HeartStrike && CurrentTargetAttackable(5.0, false, false)) && (FacingOverride(Me.CurrentTarget) && CanCastCheck("Heart Strike", false))) && (CountEnemyNear(Me, 15f) < 4.0), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Heart Strike", Me.CurrentTarget, "");
            }));
        }

        #endregion

        #region HoldSpendingRunicPower@

        private static bool HoldSpendingRunicPower()
        {
            if (PlayerRunicPower() > 80.0)
            {
                return false;
            }
            return (((PlayerRunicPower() < 50.0) && MeHasAura("Conversion")) || (((!SpellManager.HasSpell("Conversion") || PlayerRunicPower() >= 32) && THSettings.Instance.LichborneHeal && (HealWeight(Me) < THSettings.Instance.DoNotHealAbove)) && MeHasAura("Lichborne")));
        }

        #endregion

        #region HornofWinter@

        private static Composite HornofWinter()
        {
            return new Decorator(ret => (((THSettings.Instance.HornofWinter && (LastCastSpell != "Death Grip")) && ((LastCastSpell != "Howling Blast") && (LastCastSpell != "Outbreak"))) && ((Me.Combat && (PlayerRunicPower() < 80.0)) && CurrentTargetAttackable(30.0, false, false))) && CanCastCheck("Horn of Winter", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Horn of Winter", Me, "");
            }));
        }

        #endregion

        #region HornofWinterBuff@

        private static Composite HornofWinterBuff()
        {
            return new Decorator(ret => (THSettings.Instance.HornofWinter && !MeHasAura("Horn of Winter")) && CanCastCheck("Horn of Winter", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Horn of Winter", Me, "HornofWinterBuff");
            }));
        }

        #endregion

        #region HowlingBlastDebuff@

        private static DateTime LastFrostFeverDebuff;

        private static Composite HowlingBlastDebuff()
        {
            return new Decorator(ret => ((((THSettings.Instance.HowlingBlast && ((LastFrostFeverDebuff + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && (CurrentTargetAttackable(30.0, false, false) && FacingOverride(Me.CurrentTarget))) && (CanCastCheck("Howling Blast", false) && ((MyAuraTimeLeft("Frost Fever", Me.CurrentTarget) < 3000.0) || !SpellManager.HasSpell("Obliterate")))) && ((!SpellManager.HasSpell("Outbreak") || !THSettings.Instance.Outbreak) || (SpellManager.HasSpell("Outbreak") && GetSpellCooldown("Outbreak").TotalMilliseconds > 3000.0))) && !HasEnemyNearGotCCBreakonDamge(Me.CurrentTarget, 10f), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Howling Blast", Me.CurrentTarget, "HowlingBlastDebuff");
            }));
        }

        #endregion

        #region HowlingBlastAoE@

        private static Composite HowlingBlastAoE()
        {
            return new Decorator(ret => ((THSettings.Instance.HowlingBlast && CurrentTargetAttackable(30.0, false, false)) && FacingOverride(Me.CurrentTarget)) && CanCastCheck("Howling Blast", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Howling Blast", Me.CurrentTarget, "HowlingBlastAoE");
            }));
        }

        #endregion

        #region HowlingBlastAoELow@

        private static Composite HowlingBlastAoELow()
        {
            return new Decorator(ret => ((THSettings.Instance.HowlingBlast && CurrentTargetAttackable(30.0, false, false)) && (FacingOverride(Me.CurrentTarget) && !HasEnemyNearGotCCBreakonDamge(Me.CurrentTarget, 10f))) && CanCastCheck("Howling Blast", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Howling Blast", Me.CurrentTarget, "HowlingBlastAoELow");
            }));
        }

        #endregion

        #region HowlingBlastProc@

        private static DateTime LastProc;

        private static Composite HowlingBlastProc()
        {
            return new Decorator(ret => (((THSettings.Instance.HowlingBlast && ((LastProc + TimeSpan.FromMilliseconds(1500.0)) < DateTime.Now)) && (CurrentTargetAttackable(30.0, false, false) && MeHasAura("Freezing Fog"))) && (FacingOverride(Me.CurrentTarget) && CanCastCheck("Howling Blast", false))) && !HasEnemyNearGotCCBreakonDamge(Me.CurrentTarget, 10f), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Howling Blast", Me.CurrentTarget, "HowlingBlastProc");
                LastProc = DateTime.Now;
            }));
        }

        #endregion

        #region HowlingBlastDW@

        private static Composite HowlingBlastDW()
        {
            return new Decorator(ret => (((THSettings.Instance.HowlingBlast && CurrentTargetAttackable(30.0, false, false)) && (FacingOverride(Me.CurrentTarget) && CanCastCheck("Howling Blast", false))) && !CanCastCheck("Obliterate", false)) && !HasEnemyNearGotCCBreakonDamge(Me.CurrentTarget, 10f), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Howling Blast", Me.CurrentTarget, "HowlingBlastDW");
            }));
        }

        #endregion

        #region Huddle@

        private static Composite Huddle()
        {
            return new Decorator(ret => ((THSettings.Instance.Huddle && Me.GotAlivePet) && (Me.Pet.HealthPercent <= THSettings.Instance.HuddleHP)) && PetCanCastAction("Huddle"), new Styx.TreeSharp.Action(delegate(object param0)
            {
                PetCastAction("Huddle", Me.Pet);
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region IceboundFortitude@

        private static Composite IceboundFortitude()
        {
            return new Decorator(ret => ((THSettings.Instance.IceboundFortitude && Me.Combat) && (CurrentTargetAttackable(30.0, false, false) && (HealWeight(Me) <= THSettings.Instance.IceboundFortitudeHP))) && CanCastCheck("Icebound Fortitude", true), new Styx.TreeSharp.Action(delegate(object ret)
            {
                CastSpell("Icebound Fortitude", Me, "");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region IceboundFortitudeStun@

        private static Composite IceboundFortitudeStun()
        {
            return new Decorator(ret => ((THSettings.Instance.IceboundFortitudeStun && DebuffStunDuration(Me, (double)THSettings.Instance.IceboundFortitudeStunDuration)) && CurrentTargetAttackable(30.0, false, false)) && CanCastCheck("Icebound Fortitude", true), new Action(delegate
            {
                CastSpell("Icebound Fortitude", Me, "IceboundFortitudeStun");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region IcyTouch@

        private static Composite IcyTouch()
        {
            return new Decorator(ret => (((THSettings.Instance.IcyTouch && ((LastFrostFeverDebuff + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && (CurrentTargetAttackable(30.0, false, false) && FacingOverride(Me.CurrentTarget))) && (MyAuraTimeLeft("Frost Fever", Me.CurrentTarget) < 2000.0)) && CanCastCheck("Icy Touch", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Icy Touch", Me.CurrentTarget, "");
            }));
        }

        #endregion

        #region IcyTouchUnholyAoE@

        private static Composite IcyTouchUnholyAoE()
        {
            return new Decorator(ret => ((THSettings.Instance.IcyTouch && CurrentTargetAttackable(30.0, false, false)) && FacingOverride(Me.CurrentTarget)) && CanCastCheck("Icy Touch", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Icy Touch", Me.CurrentTarget, "IcyTouchUnholyAoE");
            }));
        }

        #endregion

        #region IcyTouchDebuffBlood@

        private static Composite IcyTouchDebuffBlood()
        {
            return new Decorator(ret => (((THSettings.Instance.IcyTouch && ((LastFrostFeverDebuff + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && (CurrentTargetAttackable(30.0, false, false) && FacingOverride(Me.CurrentTarget))) && (((MyAuraTimeLeft("Frost Fever", Me.CurrentTarget) < 2000.0) && CanCastCheck("Icy Touch", false)) && SpellManager.HasSpell("Outbreak"))) && (GetSpellCooldown("Outbreak").TotalMilliseconds > 3000.0), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Icy Touch", Me.CurrentTarget, "IcyTouchDebuffBlood");
            }));
        }

        #endregion

        #region IcyTouchDebuffUnholy@

        private static Composite IcyTouchDebuffUnholy()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.IcyTouch || ((LastFrostFeverDebuff + TimeSpan.FromMilliseconds(2000.0)) >= DateTime.Now)) || (!CurrentTargetAttackable(30.0, false, false) || !FacingOverride(Me.CurrentTarget))) || (((Me.FrostRuneCount <= 0) || (MyAuraTimeLeft("Frost Fever", Me.CurrentTarget) >= 1000.0)) || !CanCastCheck("Icy Touch", false)))
                {
                    return false;
                }
                return (!SpellManager.HasSpell("Outbreak") || !THSettings.Instance.Outbreak) || (SpellManager.HasSpell("Outbreak") && (GetSpellCooldown("Outbreak").TotalMilliseconds > 3000.0));
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Icy Touch", Me.CurrentTarget, "IcyTouchDebuffUnholy");
            }));
        }

        #endregion

        #region IcyTouchDebuffBloodAoE@

        private static Composite IcyTouchDebuffBloodAoE()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.IcyTouch || ((LastFrostFeverDebuff + TimeSpan.FromMilliseconds(2000.0)) >= DateTime.Now)) || (!CurrentTargetAttackable(30.0, false, false) || !FacingOverride(Me.CurrentTarget))) || (!CanCastCheck("Icy Touch", false) || ((SpellManager.HasSpell("Outbreak") && THSettings.Instance.Outbreak) && (!SpellManager.HasSpell("Outbreak") || (GetSpellCooldown("Outbreak").TotalMilliseconds <= 3000.0)))))
                {
                    return false;
                }
                return !HasEnemyDontHaveFrostFever();
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Icy Touch", Me.CurrentTarget, "IcyTouchDebuffBloodAoE");
            }));
        }

        #endregion

        #region IcyTouchDebuffFrost@

        private static Composite IcyTouchDebuffFrost()
        {
            return new Decorator(ret => ((((THSettings.Instance.IcyTouch && ((LastFrostFeverDebuff + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && (CurrentTargetAttackable(30.0, false, false) && FacingOverride(Me.CurrentTarget))) && ((MyAuraTimeLeft("Frost Fever", Me.CurrentTarget) < 3000.0) || (!SpellManager.HasSpell("Howling Blast") && (UseSpecialization == 2)))) && CanCastCheck("Icy Touch", false)) && ((!SpellManager.HasSpell("Outbreak") || !THSettings.Instance.Outbreak) || (SpellManager.HasSpell("Outbreak") && (GetSpellCooldown("Outbreak").TotalMilliseconds > 3000.0))), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Icy Touch", Me.CurrentTarget, "IcyTouchDebuffFrost");
            }));
        }

        #endregion

        #region IcyTouchDispel@

        private static Composite IcyTouchDispel()
        {
            return new Decorator(delegate(object ret)
            {
                if ((((!THSettings.Instance.IcyTouch || !CurrentTargetAttackable(30.0, false, false)) || (!Me.CurrentTarget.IsPlayer || !FacingOverride(Me.CurrentTarget))) || !HasGlyph.Contains("58631")) || ((!UnitHasAura("Hand of Protection", Me.CurrentTarget) && !UnitHasAura("Earth Shield", Me.CurrentTarget)) && ((!UnitHasAura("Nature's Swiftness", Me.CurrentTarget) && !UnitHasAura("Icy Veins", Me.CurrentTarget)) && !UnitHasAura("Master's Call", Me.CurrentTarget))))
                {
                    return false;
                }
                return CanCastCheck("Icy Touch", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Icy Touch", Me.CurrentTarget, "IcyTouchDispel");
            }));
        }

        #endregion

        #region IcyTouchDispelLowPriority@

        private static bool CanIcyTouchDispel(WoWUnit target)
        {
            if (((target == null) || !target.IsValid) || !target.IsPlayer)
            {
                return false;
            }
            return target.Buffs.Values.Any<WoWAura>(buffs => (buffs.Spell.DispelType == WoWDispelType.Magic));
        }

        private static Composite IcyTouchDispelLowPriority()
        {
            return new Decorator(ret => ((((THSettings.Instance.IcyTouch && CurrentTargetAttackable(30.0, false, false)) && (FacingOverride(Me.CurrentTarget) && HasGlyph.Contains("58631"))) && (HasMagicBuffDispel(Me.CurrentTarget) && (CanUseDeathRune() || (Me.FrostRuneCount > 0)))) && CanCastCheck("Icy Touch", false)) && CanIcyTouchDispel(Me.CurrentTarget), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Icy Touch", Me.CurrentTarget, "IcyTouchDispelLowPriority");
            }));
        }

        #endregion

        #region IcyTouchConversion@
        private static Composite IcyTouchConversion()
        {
            return new Decorator(ret => (((THSettings.Instance.IcyTouch && CurrentTargetAttackable(30.0, false, false)) && (FacingOverride(Me.CurrentTarget) && (Me.FrostRuneCount > 0))) && (Me.BloodRuneCount == 0)) && CanCastCheck("Icy Touch", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Icy Touch", Me.CurrentTarget, "IcyTouchConversion");
            }));
        }
        #endregion

        #region Interrupt@

        private static DateTime LastInterrupt = DateTime.Now;

        private static WoWUnit UnitInterrupt;

        #endregion

        #region LichborneFearVoid@

        private static void LichborneFearVoid()
        {
            if ((THSettings.Instance.LichborneFear && ((BreakCCLast + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && (DebuffFearDuration(Me, (double)THSettings.Instance.LichborneFearDuration) && CanCastCheck("Lichborne", false)))
            {
                BreakCCLast = DateTime.Now;
                CastSpell("Lichborne", Me, "LichborneFear");
            }
        }

        #endregion

        #region LichborneHeal@

        private static Composite LichborneHeal()
        {
            return new PrioritySelector(new Composite[] { new Decorator(ret => (((THSettings.Instance.LichborneHeal && (HealWeight(Me) <= THSettings.Instance.LichborneHealHP)) && (Me.Combat && (PlayerRunicPower() >= 40.0))) && !MeHasAura("Lichborne")) && CanCastCheck("Lichborne", true), new Styx.TreeSharp.Action(delegate (object ret) {
                CastSpell("Lichborne", Me, "LichborneHeal");
                return RunStatus.Failure;
            })), new Decorator(ret => ((THSettings.Instance.LichborneHeal && (HealWeight(Me) <= THSettings.Instance.LichborneHealHP)) && (Me.Combat && MeHasAura("Lichborne"))) && CanCastCheck("Death Coil", false), new Styx.TreeSharp.Action(delegate (object ret) {
                CastSpell("Death Coil", Me, "LichborneHeal - Death Coil");
                return RunStatus.Failure;
            })) });
        }

        #endregion

        #region MindFreeze@

        private static bool GetUnitMindFreezeInterrupt()
        {
            UnitInterrupt = null;
            if (InBattleground || InArena)
            {
                UnitInterrupt = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && (FacingOverride(unit) && InterruptCheck(unit, (double)(THSettings.Instance.MindFreezeInterruptMs + 0x5dc), true))) && Attackable(unit, 5));
            }
            else
            {
                UnitInterrupt = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => (((BasicCheck(unit) && (InProvingGrounds || unit.Combat)) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && ((FacingOverride(unit) && FarFriendlyPlayers.Contains(unit.CurrentTarget)) && InterruptCheck(unit, (double)(THSettings.Instance.MindFreezeInterruptMs + 0x5dc), false))) && Attackable(unit, 5));
            }
            return BasicCheck(UnitInterrupt);
        }

        //private static Composite MindFreeze()
        //{
        //    return new PrioritySelector(
        //        new Decorator(
        //            ret =>
        //            THSettings.Instance.MindFreezeInterrupt &&
        //            _lastInterrupt < DateTime.Now &&
        //            SpellManager.HasSpell("Mind Freeze") &&
        //            Me.Combat &&
        //            GetUnitMindFreezeInterrupt() &&
        //            UnitInterrupt != null && UnitInterrupt.IsValid && !InvulnerableSpell(UnitInterrupt) &&
        //            CanCastCheck("Mind Freeze"),
        //            new Action(delegate
        //                {
        //                    if (Me.IsCasting)
        //                    {
        //                        SpellManager.StopCasting();
        //                    }
        //                    FacingDelay = DateTime.Now;
        //                    if (THSettings.Instance.AutoFace &&
        //                        FacingDelay + TimeSpan.FromMilliseconds(100) > DateTime.Now &&
        //                        !Me.IsFacing(UnitInterrupt))
        //                    {
        //                        Me.SetFacing(UnitInterrupt);
        //                    }
        //                    while (UnitInterrupt.IsCasting &&
        //                           UnitInterrupt.CurrentCastTimeLeft.TotalMilliseconds >
        //                           _myLatency + THSettings.Instance.MindFreezeInterruptMs)
        //                    {
        //                        Logging.Write("Waiting for Mind Freeze");
        //                    }
        //                    if (UnitInterrupt.IsCasting &&
        //                        UnitInterrupt.CurrentCastTimeLeft.TotalMilliseconds <
        //                        _myLatency + THSettings.Instance.MindFreezeInterruptMs &&
        //                        UnitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > _myLatency ||
        //                        UnitInterrupt.IsChanneling)
        //                    {
        //                        CastSpell("Mind Freeze", UnitInterrupt);
        //                        _lastInterrupt = DateTime.Now;;
        //                        return RunStatus.Failure;
        //                    }
        //                    return RunStatus.Failure;
        //                })));
        //}

        private static void MindFreezeVoid()
        {
            if ((THSettings.Instance.MindFreezeInterrupt && ((LastInterrupt + TimeSpan.FromMilliseconds(1000.0)) < DateTime.Now)) && (CanCastCheck("Mind Freeze", true) && GetUnitMindFreezeInterrupt()))
            {
                if (Me.IsCasting)
                {
                    SpellManager.StopCasting();
                }
                SafelyFacingTarget(UnitInterrupt);
                while (UnitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > THSettings.Instance.MindFreezeInterruptMs)
                {
                    Styx.Common.Logging.Write("Waiting for Mind Freeze");
                }
                if (UnitInterrupt.IsCasting)
                {
                    CastSpell("Mind Freeze", UnitInterrupt, "MindFreezeVoid");
                    LastInterrupt = DateTime.Now;
                }
            }
        }

        #endregion

        #region NecroticStrikeStackMax@
        private static Composite NecroticStrikeStackMax()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.NecroticStrikeStack || !Me.Combat) || !CurrentTargetAttackable(5.0, false, false)) || ((Me.DeathRuneCount < THSettings.Instance.NecroticStrikeDeathRuneNumber) && ((UseSpecialization != 2) || (Me.DeathRuneCount < 2))))
                {
                    return false;
                }
                return CanCastCheck("Necrotic Strike", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                if (THSettings.Instance.NecroticStrikeStack && !NecroticStrikeSW.IsRunning)
                {
                    NecroticStrikeSW.Reset();
                    NecroticStrikeSW.Start();
                }
                if (THSettings.Instance.NecroticStrikeStackBurst && !Burst)
                {
                    Burst = true;
                    BurstLast = DateTime.Now.AddSeconds(15.0);
                    Logging.Write("Activate Burst Mode on Necrotic Unlease");
                }
                CastSpell("Necrotic Strike", Me.CurrentTarget, "NecroticStrikeStackMax");
            }));
        }
        #endregion

        #region NecroticStrikeAvailable@

        //private static bool NecroticStrikeAvailable()
        //{
        //    if (!THSettings.Instance.NecroticStrikeDebuff ||
        //        !SpellManager.HasSpell("Necrotic Strike") ||
        //        (THSettings.Instance.NecroticStrikeDebuff ||
        //         THSettings.Instance.NecroticStrikeStack) &&
        //        Me.DeathRuneCount == 0)
        //    {
        //        return false;
        //    }
        //    return true;
        //}

        #endregion

        #region NecroticStrikeStack@

        //public int CountHealerAround()
        //{
        //    return NearbyUnFriendlyPlayers.Count(
        //        unit =>
        //        TalentSort(unit) == 4);
        //}
        private static readonly Stopwatch NecroticStrikeSW = Stopwatch.StartNew();

        private static bool NecroticStrikeSWReset()
        {
            if (((THSettings.Instance.NecroticStrikeStack && (UseSpecialization == 3)) && (NecroticStrikeSW.IsRunning && (NecroticStrikeSW.ElapsedMilliseconds > 0x2710L) && !UnitHasAura("Necrotic Strike", Me.CurrentTarget))) && (GetRuneSlot() && (DeathRuneSlot < 1)))
            {
                NecroticStrikeSW.Stop();
                NecroticStrikeSW.Reset();
            }
            if (((THSettings.Instance.NecroticStrikeStack && (UseSpecialization != 3)) && (NecroticStrikeSW.IsRunning && (NecroticStrikeSW.ElapsedMilliseconds > 0xbb8L))) && (Me.DeathRuneCount < 1))
            {
                NecroticStrikeSW.Stop();
                NecroticStrikeSW.Reset();
            }
            return true;
        }

        private static Composite NecroticStrikeStack()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.NecroticStrikeStack || !Me.Combat) || (!CurrentTargetAttackable(5.0, false, false) || !FacingOverride(Me.CurrentTarget))) || (!NecroticStrikeSWReset() || (!NecroticStrikeSW.IsRunning && (Me.DeathRuneCount < THSettings.Instance.NecroticStrikeDeathRuneNumber))))
                {
                    return false;
                }
                return CanCastCheck("Necrotic Strike", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                if (THSettings.Instance.NecroticStrikeStack && !NecroticStrikeSW.IsRunning)
                {
                    NecroticStrikeSW.Reset();
                    NecroticStrikeSW.Start();
                }
                if (THSettings.Instance.NecroticStrikeStackBurst && !Burst)
                {
                    Burst = true;
                    BurstLast = DateTime.Now.AddSeconds(15.0);
                    Logging.Write("Activate Burst Mode on Necrotic Unlease");
                }
                CastSpell("Necrotic Strike", Me.CurrentTarget, "NecroticStrikeStack");
            }));
        }

        #endregion

        #region NecroticStrikeDebuff

        //private static WoWPlayer UnitNecroticStrikeDebuff;

        //private static bool GetUnitNecroticStrikeDebuff()
        //{
        //    UnitNecroticStrikeDebuff = null;

        //    UnitNecroticStrikeDebuff = (from unit in NearbyUnFriendlyPlayers
        //                                where unit != null && unit.IsValid
        //                                where !InvulnerableSpell(unit)
        //                                where FacingOverride(unit)
        //                                where TalentSort(unit) > 2
        //                                where !unit.HasAura("Necrotic Strike")
        //                                where Attackable(unit, 5)
        //                                select unit).FirstOrDefault();

        //    return UnitNecroticStrikeDebuff != null;
        //}


        //private static Composite NecroticStrikeDebuff()
        //{
        //    return new Decorator(
        //        ret =>
        //        THSettings.Instance.NecroticStrikeDebuff &&
        //        SpellManager.HasSpell("Necrotic Strike") &&
        //        !Me.Mounted &&
        //        Me.Combat &&
        //        //!Casting() &&
        //        GetUnitNecroticStrikeDebuff() &&
        //        UnitNecroticStrikeDebuff != null &&
        //        UnitNecroticStrikeDebuff.IsValid &&
        //        CanCastCheck("Necrotic Strike"),
        //        new Action(delegate
        //            {
        //                //Logging.Write(LogLevel.Diagnostic, "Obliterate");
        //                SafelyFacingTarget(UnitNecroticStrikeDebuff);
        //                CastSpell("Necrotic Strike", UnitNecroticStrikeDebuff, "NecroticStrikeDebuff");
        //            }))
        //        ;
        //}

        #endregion

        #region ObliterateAoE@

        private static Composite ObliterateAoE()
        {
            return new Decorator(ret => ((THSettings.Instance.Obliterate && (Me.UnholyRuneCount == 2)) && (CurrentTargetAttackable(5.0, false, false) && FacingOverride(Me.CurrentTarget))) && CanCastCheck("Obliterate", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Obliterate", Me.CurrentTarget, "ObliterateAoE");
            }));
        }

        #endregion

        #region ObliterateDWRunicEmpowerment@

        //private static Composite ObliterateDWRunicEmpowerment()
        //{
        //    return new Decorator(
        //        ret =>
        //        THSettings.Instance.Obliterate &&
        //        //!Casting() &&
        //        SpellManager.HasSpell("Obliterate") &&
        //        SpellManager.HasSpell("Runic Empowerment") &&
        //        CurrentTargetAttackable(5) &&
        //        MyAura("Frost Fever", Me.CurrentTarget) &&
        //        MyAura("Blood Plague", Me.CurrentTarget) &&
        //        !Me.HasAura("Freezing Fog") &&
        //        (Me.DeathRuneCount == 2 ||
        //         Me.FrostRuneCount > 0 &&
        //         Me.UnholyRuneCount > 0) &&
        //        FacingOverride(Me.CurrentTarget) &&
        //        CanCastCheck("Obliterate"),
        //        new Action(delegate
        //            {
        //                //Logging.Write(LogLevel.Diagnostic, "Obliterate");
        //                SafelyFacingTarget(Me.CurrentTarget);
        //                CastSpell("Obliterate", Me.CurrentTarget, "ObliterateDWRunicEmpowerment");
        //            }))
        //        ;
        //}

        #endregion

        #region ObliterateDWBloodTap@

        //private static Composite ObliterateDWBloodTap()
        //{
        //    return new Decorator(
        //        ret =>
        //        THSettings.Instance.Obliterate &&
        //        //!Casting() &&
        //        SpellManager.HasSpell("Obliterate") &&
        //        (SpellManager.HasSpell("Blood Tap") ||
        //         SpellManager.HasSpell("Runic Corruption") ||
        //         !SpellManager.HasSpell("Runic Empowerment") && //low level
        //         !SpellManager.HasSpell("Blood Tap") && //low level
        //         !SpellManager.HasSpell("Runic Corruption")) && //low level
        //        CurrentTargetAttackable(5) &&
        //        MyAura("Frost Fever", Me.CurrentTarget) &&
        //        MyAura("Blood Plague", Me.CurrentTarget) &&
        //        !Me.HasAura("Freezing Fog") &&
        //        Me.UnholyRuneCount == 1 &&
        //        Me.FrostRuneCount < 2 &&
        //        Me.UnholyRuneCount < 2 &&
        //        FacingOverride(Me.CurrentTarget) &&
        //        CanCastCheck("Obliterate"),
        //        new Action(delegate
        //            {
        //                //Logging.Write(LogLevel.Diagnostic, "Obliterate");
        //                SafelyFacingTarget(Me.CurrentTarget);
        //                CastSpell("Obliterate", Me.CurrentTarget, "ObliterateDWRunicEmpowerment");
        //            }))
        //        ;
        //}

        #endregion

        #region ObliterateDWKM@

        private static Composite ObliterateDWKM()
        {
            return new Decorator(ret => (((THSettings.Instance.Obliterate && CurrentTargetAttackable(5.0, false, false)) && (MyAura("Frost Fever", Me.CurrentTarget) && MyAura("Blood Plague", Me.CurrentTarget))) && ((!MeHasAura("Freezing Fog") && MeHasAura(0xc7b4)) && (FacingOverride(Me.CurrentTarget) && CanCastCheck("Obliterate", false)))) && !CanCastCheck("Frost Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Obliterate", Me.CurrentTarget, "ObliterateDWKM");
            }));
        }

        #endregion

        #region ObliterateDWSimple@

        private static Composite ObliterateDWSimple()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.Obliterate || !CurrentTargetAttackable(5.0, false, false)) || (!MyAura("Frost Fever", Me.CurrentTarget) || !MyAura("Blood Plague", Me.CurrentTarget))) || ((MeHasAura("Freezing Fog") || !FacingOverride(Me.CurrentTarget)) || !CanCastCheck("Obliterate", false)))
                {
                    return false;
                }
                return MeHasAura(0xc7b4) || (MeHasAura(0xc7b4) && !CanCastCheck("Frost Strike", false));
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Obliterate", Me.CurrentTarget, "ObliterateDWSimple");
            }));
        }

        #endregion

        #region ObliterateTH@

        private static Composite ObliterateTH()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.Obliterate || !CurrentTargetAttackable(5.0, false, false)) || (!FacingOverride(Me.CurrentTarget) || (PlayerRunicPower() > 70.0))) || (!CanUseDeathRune() && ((Me.FrostRuneCount <= 0) || (Me.UnholyRuneCount <= 0))))
                {
                    return false;
                }
                return CanCastCheck("Obliterate", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Obliterate", Me.CurrentTarget, "ObliterateTH");
            }));
        }

        #endregion

        #region ObliterateTHKM@

        private static Composite ObliterateTHKM()
        {
            return new Decorator(ret => (((THSettings.Instance.Obliterate && CurrentTargetAttackable(5.0, false, false)) && (MyAura("Frost Fever", Me.CurrentTarget) && MyAura("Blood Plague", Me.CurrentTarget))) && (MeHasAura(0xc7b4) && FacingOverride(Me.CurrentTarget))) && CanCastCheck("Obliterate", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Obliterate", Me.CurrentTarget, "ObliterateTHKM");
            }));
        }

        #endregion

        #region OutbreakPSTrigger
        private static DateTime HoldDisease = DateTime.Now;
        private static Composite OutbreakPSTrigger()
        {
            return new Decorator(ret => MeHasAura(126700) && (MeHasAura(53365) || MyAuraTimeLeft(126700,Me) < 3000) && HoldDisease <= DateTime.Now,
                new PrioritySelector(
                    new Decorator(ret => CurrentTargetAttackable(30.0, false, false) && (!InvulnerableSpell(Me.CurrentTarget) && FacingOverride(Me.CurrentTarget)) && CanCastCheck("Outbreak", false),
                        new Action(delegate
                            {
                                if (CanUseCheck(Me.Inventory.Equipped.Trinket1))
                                {
                                    Me.Inventory.Equipped.Trinket1.Use();
                                }
                                HoldDisease = DateTime.Now + TimeSpan.FromSeconds(25);
                                SafelyFacingTarget(Me.CurrentTarget);
                                CastSpell("Outbreak", Me.CurrentTarget, "");
                            })),
               new Decorator(ret => CurrentTargetAttackable(5.0, false, false) && (!InvulnerableSpell(Me.CurrentTarget) && FacingOverride(Me.CurrentTarget)) && CanCastCheck("Plague Strike", false),
                        new Action(delegate
                            {
                                if (CanUseCheck(Me.Inventory.Equipped.Trinket1))
                                {
                                    Me.Inventory.Equipped.Trinket1.Use();
                                }
                                HoldDisease = DateTime.Now + TimeSpan.FromSeconds(25);
                                SafelyFacingTarget(Me.CurrentTarget);
                                CastSpell("Plague Strike", Me.CurrentTarget, "");
                            }))));
        }
        #endregion

        #region Outbreak@

        private static Composite Outbreak()
        {
            return new Decorator(ret => (((THSettings.Instance.Outbreak && CurrentTargetAttackable(30.0, false, false)) && ((MyAuraTimeLeft("Frost Fever", Me.CurrentTarget) < 2000.0) || (MyAuraTimeLeft("Blood Plague", Me.CurrentTarget) < 2000.0))) && (!InvulnerableSpell(Me.CurrentTarget) && FacingOverride(Me.CurrentTarget))) && CanCastCheck("Outbreak", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastFrostFeverDebuff = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Outbreak", Me.CurrentTarget, "");
            }));
        }

        #endregion

        #region PathofFrost@

        private static DateTime LastPathofFrost = DateTime.Now;

        private static Composite PathofFrost()
        {
            return new Decorator(ret => ((((THSettings.Instance.AutoPathofFrost && (LastPathofFrost.AddSeconds(10.0) < DateTime.Now)) && !Me.Combat) && (Me.Mounted || Me.IsSwimming)) && !MeHasAura("Path of Frost")) && CanCastCheck("Path of Frost", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Path of Frost", Me, "");
                LastPathofFrost = DateTime.Now;
            }));
        }

        #endregion

        #region PathofFrostJump@

        //private static DateTime _pathofFrostJumpTime;

        //private static Composite PathofFrostJump()
        //{
        //    return new Decorator(
        //        ret =>
        //        Me.HasAura("Path of Frost") &&
        //        _pathofFrostJumpTime + TimeSpan.FromSeconds(10) < DateTime.Now &&
        //        Me.Mounted &&
        //        !Me.Combat &&
        //        !Me.MovementInfo.IsDescending &&
        //        !Me.MovementInfo.IsAscending &&
        //        !Me.IsFalling &&
        //        Me.IsSwimming &&
        //        CountDebuffAll(Me) <= 0,
        //        new Action(delegate
        //            {
        //                _pathofFrostJumpTime = DateTime.Now;
        //                //Logging.Write(LogLevel.Diagnostic, "PathofFrostJump");
        //                WoWMovement.Move(WoWMovement.MovementDirection.JumpAscend);
        //                return RunStatus.Failure;
        //            }));
        //}

        #endregion

        #region Pestilence@

        private static WoWUnit BestPestilenceTarget;

        private static bool GetBestPestilenceTarget()
        {
            BestPestilenceTarget = null;
            BestPestilenceTarget = (from unit in NearbyUnFriendlyUnits.Where<WoWUnit>(new Func<WoWUnit, bool>(Classname.BasicCheck))
                                    orderby MyAuraTimeLeft("Frost Fever", unit) + MyAuraTimeLeft("Blood Plague", unit) descending
                                    select unit).FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && MyAura("Frost Fever", unit)) && (MyAura("Blood Plague", unit) && FacingOverride(unit))) && Attackable(unit, 5));
            return BasicCheck(BestPestilenceTarget);
        }

        private static Composite Pestilence()
        {
            return new Decorator(ret => (((THSettings.Instance.Pestilence && (LastSpreadDiseases < DateTime.Now)) && (!SpellManager.HasSpell("Roiling Blood") && CanCastCheck("Pestilence", false))) && (!HasEnemyNearGotCCBreakonDamge(Me.CurrentTarget, (float)(10 + GlyphprivateofPestilenceBonus)) && HasEnemyDontHaveBloodPlagueorFrostFever())) && GetBestPestilenceTarget(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(BestPestilenceTarget);
                CastSpell("Pestilence", BestPestilenceTarget, "");
                LastSpreadDiseases = DateTime.Now + TimeSpan.FromMilliseconds(2000.0);
            }));
        }

        #endregion

        #region PetAttack@

        private static DateTime HoldPetAction;

        private static Composite PetAttack()
        {
            //return new Decorator(ret => ((((THSettings.Instance.PetAttack && ((HoldPetAction + TimeSpan.FromMilliseconds(4000.0)) < DateTime.Now)) && (CurrentTargetAttackableNoLoS(40.0) && Me.GotAlivePet)) && ((Me.Pet.HealthPercent >= 30.0) || (Me.Pet.Distance < 10.0))) && (Me.CurrentTarget.ZDiff < 10f)) && (((Me.Pet.CurrentTarget == null) || ((!InArena && (Me.Pet.CurrentTarget != null)) && (Me.Pet.CurrentTarget != Me.CurrentTarget))) || (((InArena && (Me.Pet.CurrentTarget != null)) && (Me.Pet.CurrentTarget != Me.CurrentTarget)) && !Me.Pet.CurrentTarget.IsPlayer)), new Styx.TreeSharp.Action(delegate(object ret)
            return new Decorator(ret => ((((THSettings.Instance.PetAttack && ((HoldPetAction + TimeSpan.FromMilliseconds(4000.0)) < DateTime.Now)) && (CurrentTargetAttackableNoLoS(40.0) && Me.GotAlivePet)) && ((Me.Pet.HealthPercent >= 30.0) || (Me.Pet.Distance < 10.0))) && (Me.CurrentTarget.ZDiff < 10f)) && ((Me.Pet.CurrentTarget == null) || (((Me.Pet.CurrentTarget != null)) && (Me.Pet.CurrentTarget != Me.CurrentTarget))), new Styx.TreeSharp.Action(delegate(object ret)            
            {
                Logging.Write("PetAttack");
                Lua.DoString("RunMacroText('/petattack');", "WoW.lua");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region PetCastAction@

        private static void PetCastAction(string action, WoWUnit on)
        {
            WoWUnit focusedUnit = null;
            WoWPetSpell spell = PetSpells.FirstOrDefault<WoWPetSpell>(p => p.ToString() == action);
            if (spell == null)
            {
                Styx.Common.Logging.Write("Your pet don't have " + action);
            }
            else if ((Me.CurrentTarget != null) && (on == Me.CurrentTarget))
            {
                Lua.DoString("CastPetAction({0}, 'target')", new object[] { spell.ActionBarIndex + 1 });
            }
            else if ((Me.CurrentTarget != null) && (on == Me))
            {
                Lua.DoString("CastPetAction({0}, 'player')", new object[] { spell.ActionBarIndex + 1 });
            }
            else if ((Me.CurrentTarget != null) && (on == Me.Pet))
            {
                Lua.DoString("CastPetAction({0}, 'pet')", new object[] { spell.ActionBarIndex + 1 });
            }
            else
            {
                if (Me.FocusedUnit != null)
                {
                    focusedUnit = Me.FocusedUnit;
                }
                StyxWoW.Me.SetFocus(on);
                Lua.DoString("CastPetAction({0}, 'focus')", new object[] { spell.ActionBarIndex + 1 });
                if (focusedUnit != null)
                {
                    StyxWoW.Me.SetFocus(focusedUnit);
                }
                else
                {
                    StyxWoW.Me.SetFocus((ulong)0L);
                }
            }
        }

        #endregion

        #region PetCanCastAction@

        private static bool PetCanCastAction(string action)
        {
            WoWPetSpell spell = PetSpells.FirstOrDefault<WoWPetSpell>(p => p.ToString() == action);
            return (((spell != null) && (spell.Spell != null)) && !spell.Spell.Cooldown);
        }

        #endregion

        #region PetFollow@

        private static Composite PetFollow()
        {
            return new Decorator(ret => ((THSettings.Instance.Follow && ((HoldPetAction + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && Me.GotAlivePet) && (Me.Pet.Distance > THSettings.Instance.FollowDistance), new Styx.TreeSharp.Action(delegate(object param0)
            {
                HoldPetAction = DateTime.Now;
                Lua.DoString("RunMacroText('/PetFollow');", "WoW.lua");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region PetLeap@

        private static Composite PetLeap()
        {
            return new Decorator(ret => ((((THSettings.Instance.LeapRange && ((HoldPetAction + TimeSpan.FromMilliseconds(3000.0)) < DateTime.Now)) && (Me.GotAlivePet && CurrentTargetAttackableNoLoS(40.0))) && (((Me.Pet.HealthPercent >= 30.0) && (Me.Pet.Location.Distance(Me.CurrentTarget.Location) > 5f)) && ((Me.Pet.Location.Distance(Me.CurrentTarget.Location) < THSettings.Instance.LeapRangeDist) && (Me.Pet.ZDiff < 20f)))) && PetCanCastAction("Leap")) && AttackableNoLoS(Me.CurrentTarget, 40), new Styx.TreeSharp.Action(delegate(object ret)
            {
                Logging.Write("LeapRange");
                PetCastAction("Leap", Me.CurrentTarget);
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region PetSpellsUpdate@

        private static readonly List<WoWPetSpell> PetSpells = new List<WoWPetSpell>();

        private static void PetSpellsUpdate()
        {
            if (Me.GotAlivePet)
            {
                Styx.Common.Logging.Write("PetSpellsUpdate");
                Styx.Common.Logging.Write("Toggle Pet Gnaw and Leap Autocast Off");
                Styx.Common.Logging.Write("Better let Combat Routine handle it.");
                Lua.DoString("RunMacroText('/petautocastoff Gnaw');", "WoW.lua");
                Lua.DoString("RunMacroText('/petautocastoff Leap');", "WoW.lua");
                Lua.DoString("RunMacroText('/petautocaston Claw');", "WoW.lua");
                PetSpells.Clear();
                PetSpells.AddRange(Me.PetSpells);
                Styx.Common.Logging.Write("Your Current Pet Action Bar:");
                foreach (WoWPetSpell spell in PetSpells)
                {
                    if (spell.Action.ToString() != "None")
                    {
                        Styx.Common.Logging.Write(spell.Action.ToString());
                    }
                    else if (spell.Spell != null)
                    {
                        Styx.Common.Logging.Write(spell.Spell.ToString());
                    }
                    else
                    {
                        Styx.Common.Logging.Write(spell.Stance.ToString());
                    }
                }
            }
        }

        #endregion

        #region PetGetSpellCooldown@

        private TimeSpan PetGetSpellCooldown(string spellname)
        {
            WoWPetSpell spell = PetSpells.FirstOrDefault<WoWPetSpell>(p => p.ToString() == spellname);
            if (spell == null)
            {
                return TimeSpan.FromMilliseconds(0.0);
            }
            return spell.Spell.CooldownTimeLeft;
        }

        #endregion

        #region PetHasSpell@

        private static bool PetHasSpell(string spellname)
        {
            if (!Me.GotAlivePet)
            {
                return false;
            }
            return (PetSpells.FirstOrDefault<WoWPetSpell>(p => (p.ToString() == spellname)) != null);
        }

        #endregion

        #region PetInterrupt@

        private static bool GetUnitPetGnawInterrupt()
        {
            UnitInterrupt = null;
            if (InBattleground || InArena)
            {
                UnitInterrupt = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && (((unit.Location.Distance(Me.Pet.Location) <= 8f) && !Invulnerable(unit)) && (!InvulnerableStun(unit) && !DebuffCCBreakonDamage(unit)))) && InterruptCheck(unit, (double)THSettings.Instance.GnawInterruptMS, true));
            }
            else
            {
                UnitInterrupt = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && ((unit.Location.Distance(Me.Pet.Location) <= 8f) && FarFriendlyPlayers.Contains(unit.CurrentTarget))) && InterruptCheck(unit, (double)THSettings.Instance.GnawInterruptMS, true));
            }
            return BasicCheck(UnitInterrupt);
        }

        private static bool GetUnitPetChargeInterrupt()
        {
            UnitInterrupt = null;
            if (InBattleground || InArena)
            {
                UnitInterrupt = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && (((unit.Location.Distance(Me.Pet.Location) >= 5f) && (unit.Location.Distance(Me.Pet.Location) <= 30f)) && (!InvulnerableSpell(unit) && InterruptCheck(unit, (double)THSettings.Instance.ChargeInterruptMS, true)))) && Attackable(unit, 40));
            }
            else
            {
                UnitInterrupt = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => (((BasicCheck(unit) && unit.Combat) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && (((unit.Location.Distance(Me.Pet.Location) >= 5f) && (unit.Location.Distance(Me.Pet.Location) <= 30f)) && (FarFriendlyPlayers.Contains(unit.CurrentTarget) && InterruptCheck(unit, (double)THSettings.Instance.ChargeInterruptMS, true)))) && Attackable(unit, 40));
            }
            return BasicCheck(UnitInterrupt);
        }

        private static void PetGnawInterruptVoid()
        {
            if (((THSettings.Instance.GnawInterrupt && ((LastInterrupt + TimeSpan.FromMilliseconds(1000.0)) < DateTime.Now)) && (Me.GotAlivePet && GetUnitPetGnawInterrupt())) && (PetCanCastAction("Gnaw") && UnitInterrupt.IsCasting))
            {
                Styx.Common.Logging.Write(Styx.Common.LogLevel.Diagnostic, "Gnaw UnitInterrupt");
                PetCastAction("Gnaw", UnitInterrupt);
                HoldPetAction = DateTime.Now;
                LastInterrupt = DateTime.Now;
            }
            if (((THSettings.Instance.ChargeInterrupt && ((LastInterrupt + TimeSpan.FromMilliseconds(1000.0)) < DateTime.Now)) && (Me.GotAlivePet && UnitHasAura("Dark Transformation", Me.Pet))) && ((PetCanCastAction("Leap") && GetUnitPetChargeInterrupt()) && UnitInterrupt.IsCasting))
            {
                Styx.Common.Logging.Write(Styx.Common.LogLevel.Diagnostic, "Leap Charge UnitInterrupt");
                PetCastAction("Leap", UnitInterrupt);
                HoldPetAction = DateTime.Now;
                LastInterrupt = DateTime.Now;
            }
        }

        #endregion

        #region PetStunEnemyLowHP@

        private static WoWUnit UnitPetStunEnemyLowHP;

        private static bool GetUnitPetGnawEnemyLowHP()
        {
            UnitPetStunEnemyLowHP = null;
            if (InBattleground || InArena)
            {
                UnitPetStunEnemyLowHP = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && (unit.Location.Distance(Me.Pet.Location) <= 8f)) && ((unit.HealthPercent <= THSettings.Instance.GnawStunEnemyHP) && !Invulnerable(unit))) && !DebuffCC(unit));
            }
            else
            {
                UnitPetStunEnemyLowHP = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => (((BasicCheck(unit) && unit.Combat) && ((unit.Location.Distance(Me.Pet.Location) <= 8f) && (unit.HealthPercent <= THSettings.Instance.GnawStunEnemyHP))) && !Invulnerable(unit)) && !DebuffCC(unit));
            }
            return BasicCheck(UnitPetStunEnemyLowHP);
        }

        private static bool GetUnitPetChargeEnemyLowHP()
        {
            UnitPetStunEnemyLowHP = null;
            if (InBattleground || InArena)
            {
                UnitPetStunEnemyLowHP = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => (((BasicCheck(unit) && (GetDistance(unit, Me.Pet) < 30f)) && ((GetDistance(unit, Me.Pet) > 5f) && (unit.HealthPercent <= THSettings.Instance.ChargeStunEnemyHP))) && !Invulnerable(unit)) && !DebuffCC(unit));
            }
            else
            {
                UnitPetStunEnemyLowHP = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => (((BasicCheck(unit) && unit.Combat) && ((GetDistance(unit, Me.Pet) < 30f) && (GetDistance(unit, Me.Pet) > 5f))) && ((unit.HealthPercent <= THSettings.Instance.ChargeStunEnemyHP) && !Invulnerable(unit))) && !DebuffCC(unit));
            }
            return BasicCheck(UnitPetStunEnemyLowHP);
        }

        //private static Composite PetStunEnemyHP()
        //{
        //    return new PrioritySelector(
        //        new Decorator(
        //            ret => THSettings.Instance.GnawStunEnemy &&
        //                   Me.GotAlivePet &&
        //                   !Me.Mounted &&
        //                   PetCanCastAction("Gnaw") &&
        //                   GetUnitPetGnawEnemyLowHP() &&
        //                   UnitPetStunEnemyLowHP != null &&
        //                   UnitPetStunEnemyLowHP.IsValid,
        //            new Action(
        //                ret =>
        //                    {
        //                        PetCastAction("Gnaw", UnitPetStunEnemyLowHP);
        //                        return RunStatus.Failure;
        //                    })
        //            ),
        //        new Decorator(
        //            ret => THSettings.Instance.ChargeStunEnemy &&
        //                   Me.GotAlivePet &&
        //                   !Me.Mounted &&
        //                   Me.Pet.HasAura("Dark Transformation") &&
        //                   PetCanCastAction("Leap") &&
        //                   GetUnitPetChargeEnemyLowHP() &&
        //                   UnitPetStunEnemyLowHP != null &&
        //                   UnitPetStunEnemyLowHP.IsValid,
        //            new Action(
        //                ret =>
        //                    {
        //                        PetCastAction("Leap", UnitPetStunEnemyLowHP);
        //                        return RunStatus.Failure;
        //                    })
        //            )
        //        );
        //}

        private static void PetStunEnemyHPVoid()
        {
            if ((THSettings.Instance.GnawStunEnemy && Me.GotAlivePet) && (PetCanCastAction("Gnaw") && GetUnitPetGnawEnemyLowHP()))
            {
                Styx.Common.Logging.Write(Styx.Common.LogLevel.Diagnostic, "Gnaw UnitPetStunEnemyLowHP");
                PetCastAction("Gnaw", UnitPetStunEnemyLowHP);
                HoldPetAction = DateTime.Now;
            }
            if (((THSettings.Instance.ChargeStunEnemy && Me.GotAlivePet) && (UnitHasAura("Dark Transformation", Me.Pet) && PetCanCastAction("Leap"))) && GetUnitPetChargeEnemyLowHP())
            {
                Styx.Common.Logging.Write(Styx.Common.LogLevel.Diagnostic, "Leap Charge UnitPetStunEnemyLowHP");
                PetCastAction("Leap", UnitPetStunEnemyLowHP);
                HoldPetAction = DateTime.Now;
            }
        }

        #endregion

        #region PetStunSaveFriendLowHP@

        private static WoWUnit UnitPetStunSaveFriendLowHP;

        private static bool GetUnitPetGnawSaveFriendLowHP()
        {
            UnitPetStunSaveFriendLowHP = null;
            if (InBattleground || InArena)
            {
                UnitPetStunSaveFriendLowHP = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => (((BasicCheck(unit) && (GetDistance(unit, Me.Pet) < 8f)) && (unit.GotTarget && FarFriendlyPlayers.Contains(unit.CurrentTarget))) && (((unit.CurrentTarget.HealthPercent <= THSettings.Instance.GnawStunFriendHP) && !DebuffCCBreakonDamage(unit)) && !InvulnerableStun(unit))) && !Invulnerable(unit));
            }
            else
            {
                UnitPetStunSaveFriendLowHP = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => (((BasicCheck(unit) && unit.Combat) && ((GetDistance(unit, Me.Pet) < 8f) && unit.GotTarget)) && ((FarFriendlyPlayers.Contains(unit.CurrentTarget) && (unit.CurrentTarget.HealthPercent <= THSettings.Instance.GnawStunFriendHP)) && (!DebuffCCBreakonDamage(unit) && !InvulnerableStun(unit)))) && !Invulnerable(unit));
            }
            return BasicCheck(UnitPetStunSaveFriendLowHP);
        }

        private static bool GetUnitPetChargeSaveFriendLowHP()
        {
            UnitPetStunSaveFriendLowHP = null;
            if (InBattleground || InArena)
            {
                UnitPetStunSaveFriendLowHP = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => (((BasicCheck(unit) && (GetDistance(unit, Me.Pet) < 30f)) && ((GetDistance(unit, Me.Pet) > 5f) && unit.GotTarget)) && ((FarFriendlyPlayers.Contains(unit.CurrentTarget) && (unit.CurrentTarget.HealthPercent <= THSettings.Instance.ChargeStunFriendHP)) && (!DebuffCCBreakonDamage(unit) && !InvulnerableStun(unit)))) && !Invulnerable(unit));
            }
            else
            {
                UnitPetStunSaveFriendLowHP = NearbyUnFriendlyUnits.FirstOrDefault<WoWUnit>(unit => ((((BasicCheck(unit) && unit.Combat) && ((GetDistance(unit, Me.Pet) < 30f) && (GetDistance(unit, Me.Pet) > 5f))) && ((unit.GotTarget && FarFriendlyPlayers.Contains(unit.CurrentTarget)) && ((unit.CurrentTarget.HealthPercent <= THSettings.Instance.ChargeStunFriendHP) && !DebuffCCBreakonDamage(unit)))) && !InvulnerableStun(unit)) && !Invulnerable(unit));
            }
            return BasicCheck(UnitPetStunSaveFriendLowHP);
        }

        //private static Composite PetStunFriendHP()
        //{
        //    return new PrioritySelector(
        //        new Decorator(
        //            ret => THSettings.Instance.GnawStunFriend &&
        //                   Me.GotAlivePet &&
        //                   !Me.Mounted &&
        //                   PetCanCastAction("Gnaw") &&
        //                   GetUnitPetGnawSaveFriendLowHP() &&
        //                   UnitPetStunSaveFriendLowHP != null &&
        //                   UnitPetStunSaveFriendLowHP.IsValid,
        //            new Action(
        //                ret =>
        //                    {
        //                        PetCastAction("Gnaw", UnitPetStunSaveFriendLowHP);
        //                        return RunStatus.Failure;
        //                    })
        //            ),
        //        new Decorator(
        //            ret => THSettings.Instance.ChargeStunEnemy &&
        //                   Me.GotAlivePet &&
        //                   !Me.Mounted &&
        //                   Me.Pet.HasAura("Dark Transformation") &&
        //                   PetCanCastAction("Leap") &&
        //                   GetUnitPetChargeSaveFriendLowHP() &&
        //                   UnitPetStunSaveFriendLowHP != null &&
        //                   UnitPetStunSaveFriendLowHP.IsValid,
        //            new Action(
        //                ret =>
        //                    {
        //                        PetCastAction("Leap", UnitPetStunSaveFriendLowHP);
        //                        return RunStatus.Failure;
        //                    })
        //            )
        //        );
        //}

        private static void PetStunFriendHPVoid()
        {
            if ((THSettings.Instance.GnawStunFriend && Me.GotAlivePet) && (PetCanCastAction("Gnaw") && GetUnitPetGnawSaveFriendLowHP()))
            {
                Styx.Common.Logging.Write(Styx.Common.LogLevel.Diagnostic, "Gnaw UnitPetStunSaveFriendLowHP");
                PetCastAction("Gnaw", UnitPetStunSaveFriendLowHP);
                HoldPetAction = DateTime.Now;
            }
            if (((THSettings.Instance.ChargeStunEnemy && Me.GotAlivePet) && (UnitHasAura("Dark Transformation", Me.Pet) && PetCanCastAction("Leap"))) && GetUnitPetChargeSaveFriendLowHP())
            {
                Styx.Common.Logging.Write(Styx.Common.LogLevel.Diagnostic, "Leap Charge UnitPetStunSaveFriendLowHP");
                PetCastAction("Leap", UnitPetStunSaveFriendLowHP);
                HoldPetAction = DateTime.Now;
            }
        }

        #endregion

        #region PlagueLeech@

        //private static Composite PlagueLeech()
        //{
        //    {
        //        return new Decorator(
        //            ret =>
        //            THSettings.Instance.PlagueLeech &&
        //            _lastCastSpell != "Plague Leech" &&
        //            SpellManager.HasSpell("Plague Leech") &&
        //            SpellManager.HasSpell("Outbreak") &&
        //            CurrentTargetAttackable(30)&&
        //            MyAura("Frost Fever", Me.CurrentTarget) &&
        //            MyAura("Blood Plague", Me.CurrentTarget) &&
        //            (Me.CurrentTarget.CurrentHealth > Me.CurrentHealth*0.8 ||
        //             IsDummy(Me.CurrentTarget)) &&
        //            (Me.BloodRuneCount < 2 &&
        //             UseRotation != "DeathKnightFrost" ||
        //             Me.DeathRuneCount < 2 ||
        //             Me.FrostRuneCount < 2 ||
        //             Me.UnholyRuneCount < 2) &&
        //            (MyAuraTimeLeft("Blood Plague", Me.CurrentTarget) < 5000 &&
        //             Me.HasAura("Freezing Fog") ||
        //             SpellManager.HasSpell("Outbreak") &&
        //             SpellManager.Spells["Outbreak"].CooldownTimeLeft.TotalMilliseconds <= 1500) &&
        //            CanCastCheck("Plague Leech"),
        //            new Action(delegate
        //                {
        //                    //Logging.Write(LogLevel.Diagnostic, "PlagueLeech");
        //                    CastSpell("Plague Leech", Me.CurrentTarget);
        //                }));
        //    }
        //}
        private static DateTime LastPlagueLeech;
        private static int DeathRuneSlot;

        private static Composite PlagueLeech()
        {
            return new Decorator(ret => ((((THSettings.Instance.PlagueLeech && ((LastPlagueLeech + TimeSpan.FromMilliseconds(1000.0)) < DateTime.Now)) && (CurrentTargetAttackable(30.0, false, false) && MyAura("Frost Fever", Me.CurrentTarget))) && (MyAura("Blood Plague", Me.CurrentTarget) && (IsDummy(Me.CurrentTarget) || (Me.CurrentTarget.CurrentHealth > (Me.CurrentHealth * 0.8))))) && (((MyTotalActiveRune() < 5) && GetRuneSlot()) && (DeathRuneSlot < 4))) && CanCastCheck("Plague Leech", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastPlagueLeech = DateTime.Now;
                CastSpell("Plague Leech", Me.CurrentTarget, "");
            }));
        }

        #endregion

        #region PlayerRunicPower@

        private static double PlayerRunicPower()
        {
            try
            {
                return (double)Me.CurrentRunicPower;
            }
            catch
            {
                Styx.Common.Logging.Write("Failed in PlayerRunicPower()");
                return 0.0;
            }
        }

        #endregion

        #region PlayerRune@

        //private static int BloodRuneCount
        //{
        //    get
        //    {
        //        //try
        //        //{
        //        //    //using (StyxWoW.Memory.AcquireFrame())
        //        //    {
        //        return Me.BloodRuneCount;
        //        //    }
        //        //}
        //        //catch
        //        //{
        //        //    Logging.Write("Failed in Me.BloodRuneCount");
        //        //    return 0;
        //        //}
        //    }
        //}

        //private static int DeathRuneCount
        //{
        //    get
        //    {
        //        //try
        //        //{
        //        //    //using (StyxWoW.Memory.AcquireFrame())
        //        //    {
        //        return Me.DeathRuneCount;
        //        //    }
        //        //}
        //        //catch
        //        //{
        //        //    Logging.Write("Failed in Me.DeathRuneCount");
        //        //    return 0;
        //        //}
        //    }
        //}

        //private static int FrostRuneCount
        //{
        //    get
        //    {
        //        //try
        //        //{
        //        //    //using (StyxWoW.Memory.AcquireFrame())
        //        //    {
        //        return Me.FrostRuneCount;
        //        //    }
        //        //}
        //        //catch
        //        //{
        //        //    Logging.Write("Failed in Me.FrostRuneCount");
        //        //    return 0;
        //        //}
        //    }
        //}

        //private static int UnholyRuneCount
        //{
        //    get
        //    {
        //        //try
        //        //{
        //        //using (StyxWoW.Memory.AcquireFrame())
        //        //{
        //        return Me.UnholyRuneCount;
        //        //}
        //        //}
        //        //catch
        //        //{
        //        //    Logging.Write("Failed in Me.UnholyRuneCount");
        //        //    return 0;
        //        //}
        //    }
        //}

        #endregion

        #region PlayerSuddenDoom@

        //private static bool PlayerSuddenDoom
        //{
        //    get
        //    {
        //        //try
        //        //{
        //        //    //using (StyxWoW.Memory.AcquireFrame())
        //        //    {
        //        if (Me.HasAura(81340))
        //        {
        //            return true;
        //        }
        //        //        return false;
        //        //    }
        //        //}
        //        //catch
        //        //{
        //        //    Logging.Write("Failed in PlayerSuddenDoom");
        //        return false;
        //        //}
        //    }
        //}

        #endregion

        #region PillarofFrost@

        private static Composite PillarofFrost()
        {
            return new Decorator(delegate(object ret)
            {
                if (!CurrentTargetAttackable(5.0, false, false) || ((((THSettings.Instance.PillarofFrost != 1) && ((THSettings.Instance.PillarofFrost != 2) || !Me.CurrentTarget.IsBoss)) && ((THSettings.Instance.PillarofFrost != 3) || !Burst)) && ((THSettings.Instance.PillarofFrost != 4) || (Me.CurrentTarget.HealthPercent > THSettings.Instance.PillarofFrostPercent))))
                {
                    return false;
                }
                return CanCastCheck("Pillar of Frost", true);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Pillar of Frost", Me, "");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region PlagueStrike@

        //private static DateTime LastBloodPlagueDebuff;

        private static Composite PlagueStrikeDebuff()
        {
            return new Decorator(ret => ((((THSettings.Instance.PlagueStrike && CurrentTargetAttackable(5.0, false, false)) && FacingOverride(Me.CurrentTarget)) && (((MyAuraTimeLeft("Blood Plague", Me.CurrentTarget) < 3000.0) || ((MyAuraTimeLeft("Frost Fever", Me.CurrentTarget) < 3000.0) && SpellManager.HasSpell("Ebon Plaguebringer"))) || !SpellManager.HasSpell("Death Strike"))) && CanCastCheck("Plague Strike", false)) && ((!THSettings.Instance.Outbreak || !SpellManager.HasSpell("Outbreak")) || (SpellManager.HasSpell("Outbreak") && (GetSpellCooldown("Outbreak").TotalMilliseconds > 3000.0))), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Plague Strike", Me.CurrentTarget, "PlagueStrikeDebuff");
            }));
        }

        #endregion

        #region PlagueStrikeBloodAoE@

        private static Composite PlagueStrikeBloodAoE()
        {
            return new Decorator(ret => (((THSettings.Instance.PlagueStrike && (LastCastSpell != "Outbreak")) && ((Me.UnholyRuneCount > 1) && CurrentTargetAttackable(5.0, false, false))) && ((FacingOverride(Me.CurrentTarget) && (Me.UnholyRuneCount > 1)) && CanCastCheck("Plague Strike", false))) && !HasEnemyDontHaveBloodPlague(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Plague Strike", Me.CurrentTarget, "PlagueStrikeBloodAoE");
            }));
        }

        #endregion

        #region PlagueStrikeFrostAoE@

        private static Composite PlagueStrikeFrostAoE()
        {
            return new Decorator(ret => ((((THSettings.Instance.PlagueStrike && !IsMoving(Me)) && CurrentTargetAttackable(5.0, false, false)) && ((Me.CurrentTarget.CurrentHealth > (Me.MaxHealth * 0.5)) || IsDummy(Me.CurrentTarget))) && (Me.UnholyRuneCount == 2)) && CanCastCheck("Plague Strike", false), new Styx.TreeSharp.Action(delegate(object ret)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Plague Strike", Me.CurrentTarget, "PlagueStrikeFrostAoE");
            }));
        }

        #endregion

        #region PlagueStrikeFrostDKKillUR@

        //private static Composite PlagueStrikeFrostDKKillUR()
        //{
        //    return new Decorator(
        //        ret =>
        //        THSettings.Instance.PlagueStrike &&
        //        SpellManager.HasSpell("Plague Strike") &&
        //        SpellManager.HasSpell("Death and Decay") &&
        //        !IsMoving(Me) &&
        //        //!Casting() &&
        //        CurrentTargetAttackable(5) &&
        //        (Me.CurrentTarget.CurrentHealth > Me.MaxHealth*0.5 ||
        //         IsDummy(Me.CurrentTarget)) &&
        //        Me.UnholyRuneCount == 2 &&
        //        CanCastCheck("Plague Strike") &&
        //        (!SpellManager.HasSpell("Death and Decay") ||
        //         SpellManager.HasSpell("Death and Decay") &&
        //         !CanCastCheck("Death and Decay")) &&
        //        (!SpellManager.HasSpell("Obliterate") ||
        //         SpellManager.HasSpell("Obliterate") &&
        //         !CanCastCheck("Obliterate")),
        //        new Action(
        //            ret =>
        //                {
        //                    LastBloodPlagueDebuff = DateTime.Now;
        //                    SafelyFacingTarget(Me.CurrentTarget);
        //                    CastSpell("Plague Strike", Me.CurrentTarget, "PlagueStrikeFrostDKKillUR");
        //                })
        //        );
        //}

        #endregion

        #region PreBuffSelector@
        private Composite _preCombatBuffBehavior;
        private Composite PreBuffSelector()
        {
            if (this._preCombatBuffBehavior == null)
            {
                Styx.Common.Logging.Write("Initializing pre-combat buff behaviours.");
                this._preCombatBuffBehavior = new PrioritySelector(new Composite[] { MainRotation() });
            }
            return null;
        }
        #endregion

        #region Presence@

        private static bool NeedResetPresence;

        private static Composite Presence()
        {
            return new Decorator(delegate(object ret)
            {
                if (!THSettings.Instance.AutoPrecence || !THSettings.Instance.FrostPresence)
                {
                    return false;
                }
                return (NeedResetPresence || ((!MeHasAura("Blood Presence") && !MeHasAura("Frost Presence")) && !MeHasAura("Unholy Presence"))) || (THSettings.Instance.LastSavedSpec != GetCurrentSpec());
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                if (((UseSpecialization == 2) && !MeHasAura("Frost Presence")) && CanCastCheck("Frost Presence", false))
                {
                    CastSpell("Frost Presence", Me, "");
                    NeedResetPresence = false;
                }
                if (((UseSpecialization == 1) && !MeHasAura("Blood Presence")) && CanCastCheck("Blood Presence", false))
                {
                    CastSpell("Blood Presence", Me, "");
                    NeedResetPresence = false;
                }
                if (((UseSpecialization == 3) && !MeHasAura("Unholy Presence")) && CanCastCheck("Unholy Presence", false))
                {
                    CastSpell("Unholy Presence", Me, "");
                    NeedResetPresence = false;
                }
                NeedResetPresence = false;
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region Selector@
        #region RotationSelector@
        private Composite _combatBehavior;
        private Composite RotationSelector()
        {
            if (this._combatBehavior == null)
            {
                Styx.Common.Logging.Write("Initializing combat behaviours.");
                this._combatBehavior = new PrioritySelector(new Composite[] { MainRotation() });
            }
            return null;
        }
        #endregion

        #region RestSelector
        //private Composite _restBehavior;
        //private Composite RestSelector()
        //{
        //    if (this._restBehavior == null)
        //    {
        //        Styx.Common.Logging.Write("Initializing rest behaviours.");
        //        this._restBehavior = new PrioritySelector(new Composite[] { RestRotation() });
        //    }
        //    return null;
        //}
        #endregion

        #region DeathSelector
        private Composite _deathBehavior;
        private Composite DeathSelector()
        {
            if (this._deathBehavior == null)
            {
                Styx.Common.Logging.Write("Initializing death behaviours.");
                this._deathBehavior = new PrioritySelector(new Composite[] { DeathRotation() });
            }
            return null;
        }
        #endregion

        #region RestRotation
        //private static Composite RestRotation()
        //{
        //    return new Decorator(ret => ((((THSettings.Instance.UseFood && (Me.HealthPercent <= THSettings.Instance.UseFoodHP)) && (!Me.Combat && !Me.IsDead)) && ((!Me.IsGhost && !IsOverrideModeOn) && (!Me.IsCasting && !Me.IsSwimming))) && !MeHasAura("Food")) && (Consumable.GetBestFood(true) != null), new Styx.TreeSharp.Action(delegate(object param0)
        //    {
        //        Styx.Common.Logging.Write("Using Food");
        //        if (IsMoving(Me))
        //        {
        //            WoWMovement.MoveStop();
        //        }
        //        Rest.FeedImmediate();
        //        new WaitContinue(1, ret => false, new ActionAlwaysSucceed());
        //    }));
        //}
        #endregion
        private static double MobsNearby;
        private static string SelfRezSpell;
        private static DateTime NextSuppressMessage = DateTime.MinValue;
        private static Composite DeathRotation()
        {
            Composite[] children = new Composite[] { new Styx.TreeSharp.Action(delegate (object r) {
                Styx.Common.Logging.Write("Waiting up to {0} seconds for clear area to use {1}...", new object[] { 10, SelfRezSpell });
            }), new Wait(10, delegate (object until) {
                MobsNearby = CountEnemyNear(Me, 20f);
                if ((MobsNearby > 0.0) && !Me.IsAlive)
                {
                    return Me.IsGhost;
                }
                return true;
            }, new Styx.TreeSharp.Action(delegate (object r) {
                if (Me.IsGhost)
                {
                    Styx.Common.Logging.Write("Insignia taken or corpse release by something other than Singular...");
                    return RunStatus.Failure;
                }
                if (Me.IsAlive)
                {
                    Styx.Common.Logging.Write("Ressurected by something other than Singular...");
                    return RunStatus.Failure;
                }
                return RunStatus.Success;
            })), new DecoratorContinue(req => MobsNearby > 0.0, new Styx.TreeSharp.Action(delegate (object r) {
                Styx.Common.Logging.Write("Still {0} enemies within {1} yds, skipping {2}", new object[] { MobsNearby, 20, SelfRezSpell });
                return RunStatus.Failure;
            })), new Styx.TreeSharp.Action(delegate (object r) {
                Styx.Common.Logging.Write("Ressurrecting Singular by invoking {0}...", new object[] { SelfRezSpell });
            }), new Styx.TreeSharp.Action(delegate (object r) {
                Lua.DoString("UseSoulstone()", "WoW.lua");
            }), new WaitContinue(1, delegate (object until) {
                if (!Me.IsAlive)
                {
                    return Me.IsGhost;
                }
                return true;
            }, new ActionAlwaysSucceed()) };
            return new Decorator(delegate(object req)
            {
                if (Me.IsAlive || Me.IsGhost)
                {
                    return false;
                }
                List<string> returnValues = Lua.GetReturnValues("return HasSoulstone()", "hawker.lua");
                if (((returnValues == null) || (returnValues.Count == 0)) || (string.IsNullOrEmpty(returnValues[0]) || (returnValues[0].ToLower() == "nil")))
                {
                    return false;
                }
                if (!THSettings.Instance.AutoMove)
                {
                    if (NextSuppressMessage < DateTime.Now)
                    {
                        NextSuppressMessage = DateTime.Now.AddSeconds(10.0);
                        Styx.Common.Logging.Write("Suppressing {0} behavior since movement disabled...", new object[] { returnValues[0] });
                    }
                    return false;
                }
                SelfRezSpell = returnValues[0];
                return true;
            }, new Sequence(children));
        }

        #endregion

        #region RaiseAlly@

        private static WoWPlayer UnitRaiseAlly;
        private static DateTime GetUnitRaiseAllyLastSearch;

        private static bool GetUnitRaiseAlly()
        {
            GetUnitRaiseAllyLastSearch = DateTime.Now;
            UnitRaiseAlly = null;
            UnitRaiseAlly = (from unit in ObjectManager.GetObjectsOfType<WoWPlayer>(false, false)
                             orderby unit.MaxHealth
                             select unit).FirstOrDefault<WoWPlayer>(unit => (((unit != null) && unit.IsValid) && (!unit.IsAlive && (unit.Distance < 40.0))) && InLineOfSpellSightCheck(unit));
            return BasicCheck(UnitRaiseAlly);
        }

        private static Composite RaiseAlly()
        {
            return new Decorator(ret => ((((THSettings.Instance.AutoRaiseAlly && ((GetUnitRaiseAllyLastSearch + TimeSpan.FromMilliseconds(10000.0)) < DateTime.Now)) && Me.Combat) && (InDungeon || InRaid)) && ((PlayerRunicPower() >= 30.0) && CanCastCheck("Raise Ally", false))) && GetUnitRaiseAlly(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Raise Ally", UnitRaiseAlly, "RaiseAlly");
            }));
        }

        #endregion

        #region RaiseDead@

        private static Composite RaiseDead()
        {
            return new Decorator(delegate(object ret)
            {
                if ((((!CurrentTargetAttackable(5.0, false, false) || Me.GotAlivePet) || ((Me.Minions.Count != 0) || (Me.CurrentHealth <= THSettings.Instance.UrgentHeal))) || ((Me.CurrentTarget.CurrentHealth <= (Me.CurrentHealth * 0.8)) && !IsDummy(Me.CurrentTarget))) || ((((THSettings.Instance.RaiseDead != 1) && ((THSettings.Instance.RaiseDead != 2) || !Me.CurrentTarget.IsBoss)) && ((THSettings.Instance.RaiseDead != 3) || !Burst)) && ((THSettings.Instance.RaiseDead != 4) || (Me.CurrentTarget.HealthPercent > THSettings.Instance.RaiseDeadPercent))))
                {
                    return false;
                }
                return CanCastCheck("Raise Dead", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Raise Dead", Me, "");
            }));
        }

        #endregion

        #region RaiseDeadUnholy@

        private static Composite RaiseDeadUnholy()
        {
            return new Decorator(ret => !Me.GotAlivePet && CanCastCheck("Raise Dead", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Raise Dead", Me, "RaiseDeadUnholy");
            }));
        }

        #endregion

        #region RemorselessWinter@

        private static Composite RemorselessWinter()
        {
            return new Decorator(ret => ((THSettings.Instance.RemorselessWinter && Me.Combat) && (CurrentTargetAttackable(8.0, false, false) && (HealWeight(Me) <= THSettings.Instance.RemorselessWinterHP))) && CanCastCheck("Remorseless Winter", true), new Styx.TreeSharp.Action(delegate(object ret)
            {
                CastSpell("Remorseless Winter", Me, "RemorselessWinterHP");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region RemorselessWinterEnemy@

        private static Composite RemorselessWinterEnemyLowHP()
        {
            return new Decorator(ret => ((THSettings.Instance.RemorselessWinterEnemyLow && Me.Combat) && (CurrentTargetAttackable(8.0, false, false) && (Me.CurrentTarget.HealthPercent <= THSettings.Instance.RemorselessWinterEnemyLowHP))) && CanCastCheck("Remorseless Winter", true), new Styx.TreeSharp.Action(delegate(object ret)
            {
                LastShield = DateTime.Now;
                CastSpell("Remorseless Winter", Me, "RemorselessWinterEnemyLowHP");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region RemorselessWinterEnemy@

        private static Composite RemorselessWinterEnemyNumber()
        {
            return new Decorator(ret => ((THSettings.Instance.RemorselessWinterEnemy && Me.Combat) && (CurrentTargetAttackable(8.0, false, false) && CanCastCheck("Remorseless Winter", true))) && (CountEnemyNearNoCC(Me, 8f) >= THSettings.Instance.RemorselessWinterEnemyNumber), new Styx.TreeSharp.Action(delegate(object ret)
            {
                LastShield = DateTime.Now;
                CastSpell("Remorseless Winter", Me, "RemorselessWinterEnemyNumber");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region RemorselessWinterBurst@

        private static Composite RemorselessWinterBurst()
        {
            return new Decorator(ret => ((THSettings.Instance.RemorselessWinterBurst && Burst) && (Me.Combat && CurrentTargetAttackable(8.0, false, false))) && CanCastCheck("Remorseless Winter", true), new Styx.TreeSharp.Action(delegate(object ret)
            {
                CastSpell("Remorseless Winter", Me, "RemorselessWinterBurst");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region RestRotation@

        //private static Composite RestRotation()
        //{
        //    return new Decorator(ret => ((((THSettings.Instance.UseFood && (HealWeight(Me) <= THSettings.Instance.UseFoodHP)) && (!Me.Combat && !Me.IsDead)) && ((!Me.IsGhost && !IsOverrideModeOn) && (!Me.IsCasting && !Me.IsSwimming))) && !MeHasAura("Food")) && (Consumable.GetBestFood(true) != null), new Styx.TreeSharp.Action(delegate(object param0)
        //    {
        //        Styx.Common.Logging.Write("Using Food");
        //        if (IsMoving(Me))
        //        {
        //            WoWMovement.MoveStop();
        //        }
        //        Rest.FeedImmediate();
        //        new WaitContinue(1, ret => false, new ActionAlwaysSucceed());
        //    }));
        //}

        #endregion

        #region RuneStrike@

        private static Composite RuneStrike()
        {
            return new Decorator(ret => ((THSettings.Instance.RuneStrike && CurrentTargetAttackable(5.0, false, false)) && (!HoldSpendingRunicPower() && (PlayerRunicPower() >= 50.0))) && CanCastCheck("Rune Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Rune Strike", Me.CurrentTarget, "");
            }));
        }

        #endregion

        #region RuneStrikeCap@

        private static Composite RuneStrikeCap()
        {
            return new Decorator(ret => (((THSettings.Instance.RuneStrike && ((LastCap + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && (CurrentTargetAttackable(5.0, false, false) && (PlayerRunicPower() >= 60.0))) && !HoldSpendingRunicPower()) && CanCastCheck("Rune Strike", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                LastCap = DateTime.Now;
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Rune Strike", Me.CurrentTarget, "RuneStrikeCap");
            }));
        }

        #endregion

        #region RuneTap@

        private static Composite RuneTap()
        {
            return new Decorator(ret => ((THSettings.Instance.RuneTap && Me.Combat) && (CurrentTargetAttackable(30.0, false, false) && (HealWeight(Me) <= THSettings.Instance.RuneTapHP))) && CanCastCheck("Rune Tap", true), new Styx.TreeSharp.Action(delegate(object ret)
            {
                CastSpell("Rune Tap", Me, "");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region ScourgeStrike@

        private static Composite ScourgeStrike()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.ScourgeStrike || !CurrentTargetAttackable(5.0, false, false)) || !FacingOverride(Me.CurrentTarget)) || (!CanUseDeathRune() && (Me.UnholyRuneCount <= 0)))
                {
                    return false;
                }
                return CanCastCheck("Scourge Strike", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Scourge Strike", Me.CurrentTarget, "ScourgeStrike");
            }));
        }

        #endregion

        #region ScourgeStrike90@

        private static Composite ScourgeStrike90()
        {
            return new Decorator(delegate(object ret)
            {
                if (((!THSettings.Instance.ScourgeStrike || !CurrentTargetAttackable(5.0, false, false)) || (!FacingOverride(Me.CurrentTarget) || (PlayerRunicPower() >= 90.0))) || (!CanUseDeathRune() && (Me.UnholyRuneCount <= 0)))
                {
                    return false;
                }
                return CanCastCheck("Scourge Strike", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Scourge Strike", Me.CurrentTarget, "ScourgeStrike90");
            }));
        }

        #endregion

        #region SoulReaper@

        private static Composite SoulReaper()
        {
            return new Decorator(ret => ((THSettings.Instance.SoulReaper && CurrentTargetAttackable(5.0, false, false)) && (Me.CurrentTarget.HealthPercent <= THSettings.Instance.SoulReaperHP)) && CanCastCheck("Soul Reaper", false), new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Soul Reaper", Me.CurrentTarget, "");
            }));
        }

        #endregion

        #region Strangulate@

        private static bool GetUnitStrangulateInterrupt()
        {
            UnitInterrupt = null;
            if (InBattleground || InArena)
            {
                UnitInterrupt = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => ((BasicCheck(unit) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && ((((unit.Distance <= 30.0) && !Invulnerable(unit)) && (!InvulnerableSpell(unit) && !DebuffCCBreakonDamage(unit))) && (FacingOverride(unit) && InterruptCheck(unit, (double)THSettings.Instance.StrangulateInterruptMs, false)))) && InLineOfSpellSightCheck(unit));
            }
            else
            {
                UnitInterrupt = NearbyUnFriendlyPlayers.FirstOrDefault<WoWUnit>(unit => (((BasicCheck(unit) && unit.Combat) && ((THSettings.Instance.InterruptAll || ((THSettings.Instance.InterruptTarget && (Me.CurrentTarget != null)) && (unit == Me.CurrentTarget))) || ((THSettings.Instance.InterruptFocus && (Me.FocusedUnit != null)) && (unit == Me.FocusedUnit)))) && (((unit.Distance <= 30.0) && FacingOverride(unit)) && (FarFriendlyPlayers.Contains(unit.CurrentTarget) && InterruptCheck(unit, (double)THSettings.Instance.StrangulateInterruptMs, false)))) && InLineOfSpellSightCheck(unit));
            }
            return BasicCheck(UnitInterrupt);
        }

        private static void StrangulateVoid()
        {
            if (((THSettings.Instance.StrangulateInterrupt && ((LastInterrupt + TimeSpan.FromMilliseconds(1000.0)) < DateTime.Now)) && (Me.Combat && CanCastCheck("Strangulate", true))) && GetUnitStrangulateInterrupt())
            {
                if (Me.IsCasting)
                {
                    SpellManager.StopCasting();
                }
                FacingDelay = DateTime.Now;
                if ((THSettings.Instance.AutoFace && ((FacingDelay + TimeSpan.FromMilliseconds(100.0)) > DateTime.Now)) && !Me.IsFacing(UnitInterrupt))
                {
                    Me.SetFacing(UnitInterrupt);
                }
                //new Wait(TimeSpan.FromMilliseconds(2000.0), ret => !UnitInterrupt.IsCasting || (UnitInterrupt.IsCasting && (UnitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > (THSettings.Instance.StrangulateInterruptMs + MyLatency))), new ActionAlwaysSucceed());
                while (UnitInterrupt.CurrentCastTimeLeft.TotalMilliseconds > THSettings.Instance.StrangulateInterruptMs)
                {
                    Styx.Common.Logging.Write("Waiting for Strangulate");
                }
                if (UnitInterrupt.IsCasting)
                {
                    CastSpell("Strangulate", UnitInterrupt, "StrangulateVoid");
                    LastInterrupt = DateTime.Now;
                }
            }
        }

        #endregion

        #region StrangulateLow@

        private static WoWUnit UnitStrangulateLow;

        private static bool GetUnitStrangulateLow()
        {
            UnitStrangulateLow = null;
            UnitStrangulateLow = (from unit in NearbyUnFriendlyPlayers.Where<WoWUnit>(new Func<WoWUnit, bool>(Classname.BasicCheck))
                                  orderby unit.CurrentHealth
                                  select unit).FirstOrDefault<WoWUnit>(unit => (((unit.HealthPercent <= THSettings.Instance.StrangulateLowHP) && !MyAura("Remorseless Winter", unit)) && (TalentSort(unit) >= 3)) && Attackable(unit, 40));
            return BasicCheck(UnitStrangulateLow);
        }

        private static Composite StrangulateLow()
        {
            return new Decorator(ret => ((THSettings.Instance.StrangulateLow && (InArena || InBattleground)) && (Me.Combat && CanCastCheck("Strangulate", true))) && GetUnitStrangulateLow(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                CastSpell("Strangulate", UnitStrangulateLow, "StrangulateLow");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region TargetMyPetTarget@

        private static WoWUnit UnitAttackingMyPet;

        private static bool GetUnitAttackingMyPet()
        {
            UnitAttackingMyPet = null;
            UnitAttackingMyPet = (from unit in FarUnFriendlyUnits.Where<WoWUnit>(new Func<WoWUnit, bool>(Classname.BasicCheck))
                                  orderby unit.ThreatInfo.RawPercent descending
                                  select unit).FirstOrDefault<WoWUnit>(delegate(WoWUnit unit)
            {
                if (!unit.Combat || !unit.GotTarget)
                {
                    return false;
                }
                if (unit.CurrentTarget != Me)
                {
                    return unit.CurrentTarget.CreatedByUnit == Me;
                }
                return true;
            });
            return BasicCheck(UnitAttackingMyPet);
        }

        private static Composite TargetMyPetTarget()
        {
            return new Decorator(ret => (((!CurrentTargetAttackable(40.0, false, false) && Me.Combat) && (IsUsingAFKBot && !InArena)) && !InBattleground) && GetUnitAttackingMyPet(), new Styx.TreeSharp.Action(delegate(object param0)
            {
                Logging.Write(Styx.Common.LogLevel.Diagnostic, "TargetMyPetTarget");
                UnitAttackingMyPet.Target();
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region UnholyBlight@

        private static Composite UnholyBlight()
        {
            return new Decorator(delegate(object ret)
            {
                if ((!THSettings.Instance.UnholyBlight || !CurrentTargetAttackable(10.0, false, false)) || ((MyAuraTimeLeft("Frost Fever)", Me.CurrentTarget) >= 2000.0) && (MyAuraTimeLeft("Blood Plague)", Me.CurrentTarget) >= 2000.0)))
                {
                    return false;
                }
                return CanCastCheck("Unholy Blight", false);
            }, new Styx.TreeSharp.Action(delegate(object param0)
            {
                SafelyFacingTarget(Me.CurrentTarget);
                CastSpell("Unholy Blight", Me, "");
            }));
        }

        #endregion

        #region VampiricBlood@

        private static Composite VampiricBlood()
        {
            return new Decorator(ret => ((THSettings.Instance.VampiricBlood && Me.Combat) && (HealWeight(Me) <= THSettings.Instance.VampiricBloodHP)) && CanCastCheck("Vampiric Blood", true), new Styx.TreeSharp.Action(delegate(object ret)
            {
                CastSpell("Vampiric Blood", Me, "");
                return RunStatus.Failure;
            }));
        }

        #endregion

        #region UnholyPresence@

        private static Composite UnholyPresenceSwap()
        {
            return new Decorator(
                ret => THSettings.Instance.AutoPrecence && 
                       PresenceSwapLast + TimeSpan.FromMilliseconds((double)THSettings.Instance.PresenceSwapTimeout) <= DateTime.Now &&
                       !MeHasAura("Unholy Presence") && !MeHasAura("Alliance Flag") && !MeHasAura("Horde Flag") && !MeHasAura("Netherstorm Flag") && !MeHasAura("Orb of Power") &&
                       (BasicCheck(Me.CurrentTarget)) &&
                       ((InArena && (CountDPSTarget(Me) < 1 || ((HealWeight(Me) >= THSettings.Instance.BloodPresenceHP) && HasHealerWithMe()))) ||
                        (!InArena && HealWeight(Me) >= THSettings.Instance.BloodPresenceHP)) && 
                       CanCastCheck("Unholy Presence"),
                       new Action(delegate
                       {
                            PresenceSwapLast = DateTime.Now;
                            CastSpell("Unholy Presence", Me, "UnholyPresence");
                        }));
        }


        #endregion

        #region UseRacial@

        private static Composite UseRacial()
        {
            return new PrioritySelector(new Composite[] { new Decorator(ret => (((Me.Combat && THSettings.Instance.AutoRacial) && (((BreakCCLast + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now) && DebuffCCDuration(Me, 3000.0, false))) && !MeHasAura("Sap")) && CanCastCheck("Every Man for Himself", true), new Styx.TreeSharp.Action(delegate (object param0) {
                if ((THSettings.Instance.AutoTarget && (Me.CurrentTarget == null)) && ((MyLastTarget != null) && MyLastTarget.IsValid))
                {
                    MyLastTarget.Target();
                }
                if (DebuffCCBreakonDamage(Me) && DebuffDot(Me))
                {
                    Styx.Common.Logging.Write("Waiting for Dot / Hand of Sacrifice break it!");
                }
                else
                {
                    BreakCCLast = DateTime.Now;
                    Styx.Common.Logging.Write("Use: Every Man for Himself");
                    CastSpell("Every Man for Himself", Me, "");
                }
                return RunStatus.Failure;
            })), new Decorator(ret => ((Me.Combat && THSettings.Instance.AutoRacial) && (HealWeight(Me) < THSettings.Instance.UrgentHeal)) && CanCastCheck("Stoneform", true), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Stoneform");
                CastSpell("Stoneform", Me, "");
                return RunStatus.Failure;
            })), new Decorator(ret => ((Me.Combat && THSettings.Instance.AutoRacial) && (HealWeight(Me) < THSettings.Instance.UrgentHeal)) && CanCastCheck("Gift of the Naaru", true), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Gift of the Naaru");
                CastSpell("Gift of the Naaru", Me, "");
            })) });
        }

        #endregion

        #region UseTrinket

        private static Composite UseTrinket()
        {
            return new PrioritySelector(new Composite[] { new Decorator(ret => ((((THSettings.Instance.Trinket1 == 1) && Me.Combat) && (CurrentTargetAttackable(10.0, false, false) && FacingOverride(Me.CurrentTarget))) && (Me.Inventory.Equipped.Trinket1 != null)) && CanUseCheck(Me.Inventory.Equipped.Trinket1), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name + " on Cooldown");
                StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.Trinket1 == 2) && Me.Combat) && (CurrentTargetAttackable(10.0, false, false) && Me.CurrentTarget.IsBoss)) && (FacingOverride(Me.CurrentTarget) && (Me.Inventory.Equipped.Trinket1 != null))) && CanUseCheck(Me.Inventory.Equipped.Trinket1), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name + " on Cooldown (Boss Only)");
                StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.Trinket1 == 3) && Burst) && (Me.Combat && CurrentTargetAttackable(15.0, false, false))) && (Me.Inventory.Equipped.Trinket1 != null)) && CanUseCheck(Me.Inventory.Equipped.Trinket1), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name + " on Burst Mode");
                StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.Trinket1 == 4) && ((BreakCCLast + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && (Me.Combat && (Me.Inventory.Equipped.Trinket1 != null))) && (DebuffCCDuration(Me, 3000.0, false) && !MeHasAura("Sap"))) && CanUseCheck(Me.Inventory.Equipped.Trinket1), new Styx.TreeSharp.Action(delegate (object param0) {
                BreakCCLast = DateTime.Now;
                StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                Styx.Common.Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name + " on Lose Control");
                return RunStatus.Failure;
            })), new Decorator(ret => (((THSettings.Instance.Trinket1 == 5) && Me.Combat) && ((Me.Inventory.Equipped.Trinket1 != null) && (HealWeight(Me) < THSettings.Instance.Trinket1HP))) && CanUseCheck(Me.Inventory.Equipped.Trinket1), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name + " on Low HP");
                StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.Trinket1 == 6) && Me.Combat) && ((Me.Inventory.Equipped.Trinket1 != null) && CurrentTargetAttackable(10.0, false, false))) && (Me.CurrentTarget.HealthPercent < THSettings.Instance.Trinket1HP)) && CanUseCheck(Me.Inventory.Equipped.Trinket1), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket1.Name + " on Enemy Unit Low HP");
                StyxWoW.Me.Inventory.Equipped.Trinket1.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.Trinket2 == 1) && Me.Combat) && (CurrentTargetAttackable(10.0, false, false) && FacingOverride(Me.CurrentTarget))) && (Me.Inventory.Equipped.Trinket2 != null)) && CanUseCheck(Me.Inventory.Equipped.Trinket2), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name + " on Cooldown");
                StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.Trinket2 == 2) && Me.Combat) && (CurrentTargetAttackable(10.0, false, false) && Me.CurrentTarget.IsBoss)) && (FacingOverride(Me.CurrentTarget) && (Me.Inventory.Equipped.Trinket2 != null))) && CanUseCheck(Me.Inventory.Equipped.Trinket2), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name + " on Cooldown (Boss Only)");
                StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.Trinket2 == 3) && Burst) && (Me.Combat && CurrentTargetAttackable(15.0, false, false))) && (Me.Inventory.Equipped.Trinket2 != null)) && CanUseCheck(Me.Inventory.Equipped.Trinket2), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name + " on Burst Mode");
                StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.Trinket2 == 4) && ((BreakCCLast + TimeSpan.FromMilliseconds(2000.0)) < DateTime.Now)) && (Me.Combat && (Me.Inventory.Equipped.Trinket2 != null))) && (DebuffCCDuration(Me, 3000.0, false) && !MeHasAura("Sap"))) && CanUseCheck(Me.Inventory.Equipped.Trinket2), new Styx.TreeSharp.Action(delegate (object param0) {
                BreakCCLast = DateTime.Now;
                StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                Styx.Common.Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name + " on Lose Control");
                return RunStatus.Failure;
            })), new Decorator(ret => (((THSettings.Instance.Trinket2 == 5) && Me.Combat) && ((Me.Inventory.Equipped.Trinket2 != null) && (HealWeight(Me) < THSettings.Instance.Trinket2HP))) && CanUseCheck(Me.Inventory.Equipped.Trinket2), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name + " on Low HP");
                StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.Trinket2 == 6) && Me.Combat) && ((Me.Inventory.Equipped.Trinket2 != null) && CurrentTargetAttackable(10.0, false, false))) && (Me.CurrentTarget.HealthPercent < THSettings.Instance.Trinket2HP)) && CanUseCheck(Me.Inventory.Equipped.Trinket2), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Activate " + StyxWoW.Me.Inventory.Equipped.Trinket2.Name + " on Enemy Unit Low HP");
                StyxWoW.Me.Inventory.Equipped.Trinket2.Use();
                return RunStatus.Failure;
            })) });
        }

        #endregion

        #region UseProfession

        private static Composite UseProfession()
        {
            return new PrioritySelector(new Composite[] { new Decorator(ret => ((((THSettings.Instance.ProfBuff == 1) && Me.Combat) && (CurrentTargetAttackable(10.0, false, false) && FacingOverride(Me.CurrentTarget))) && (Me.Inventory.Equipped.Hands != null)) && CanUseCheck(Me.Inventory.Equipped.Hands), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Use: Gloves Buff Activated on Cooldown");
                StyxWoW.Me.Inventory.Equipped.Hands.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.ProfBuff == 2) && Me.Combat) && (CurrentTargetAttackable(10.0, false, false) && Me.CurrentTarget.IsBoss)) && (FacingOverride(Me.CurrentTarget) && (Me.Inventory.Equipped.Hands != null))) && CanUseCheck(Me.Inventory.Equipped.Hands), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Use: Gloves Buff Activated on Cooldown (Boss Only)");
                StyxWoW.Me.Inventory.Equipped.Hands.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.ProfBuff == 3) && Burst) && (Me.Combat && CurrentTargetAttackable(15.0, false, false))) && (Me.Inventory.Equipped.Hands != null)) && CanUseCheck(Me.Inventory.Equipped.Hands), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Use: Gloves Buff Activated on Burst Mode");
                StyxWoW.Me.Inventory.Equipped.Hands.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => (((THSettings.Instance.ProfBuff == 4) && Me.Combat) && (CurrentTargetAttackable(10.0, false, false) && DebuffCCDuration(Me, 3000.0, false))) && CanUseCheck(Me.Inventory.Equipped.Hands), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Use: Gloves Buff Activated on Lose Control");
                StyxWoW.Me.Inventory.Equipped.Hands.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.ProfBuff == 5) && Me.Combat) && ((Me.Inventory.Equipped.Hands != null) && CurrentTargetAttackable(10.0, false, false))) && (HealWeight(Me) < THSettings.Instance.ProfBuffHP)) && CanUseCheck(Me.Inventory.Equipped.Hands), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Use: GLoves Buff Activated on Low HP");
                StyxWoW.Me.Inventory.Equipped.Hands.Use();
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.ProfBuff == 6) && Me.Combat) && ((Me.Inventory.Equipped.Hands != null) && CurrentTargetAttackable(10.0, false, false))) && (!Me.CurrentTarget.IsPet && (Me.CurrentTarget.HealthPercent < THSettings.Instance.ProfBuffHP))) && CanUseCheck(Me.Inventory.Equipped.Hands), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Use: Gloves Buff Activated on Enemy Unit Low HP");
                StyxWoW.Me.Inventory.Equipped.Hands.Use();
                return RunStatus.Failure;
            })), new Decorator(delegate (object ret) {
                if ((((THSettings.Instance.ProfBuff != 1) || !Me.Combat) || !CurrentTargetAttackable(10.0, false, false)) || (!MeHasAura(0xc847) && !MeHasAura("Unholy Frenzy")))
                {
                    return false;
                }
                return CanCastCheck("Lifeblood", true);
            }, new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Use: Lifeblood Activated on Cooldown");
                CastSpell("Lifeblood", Me, "");
                return RunStatus.Failure;
            })), new Decorator(ret => (((THSettings.Instance.ProfBuff == 2) && Me.Combat) && (CurrentTargetAttackable(10.0, false, false) && MeHasAura(0xc847))) && CanCastCheck("Lifeblood", true), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Use: Lifeblood Activated on Cooldown (Boss Only)");
                CastSpell("Lifeblood", Me, "");
                return RunStatus.Failure;
            })), new Decorator(ret => (((THSettings.Instance.ProfBuff == 3) && Burst) && (Me.Combat && CurrentTargetAttackable(15.0, false, false))) && CanCastCheck("Lifeblood", true), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Use: Lifeblood Activated on Burst Mode");
                CastSpell("Lifeblood", Me, "");
                return RunStatus.Failure;
            })), new Decorator(ret => (((THSettings.Instance.ProfBuff == 4) && Me.Combat) && DebuffCCDuration(Me, 3000.0, false)) && CanCastCheck("Lifeblood", true), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Use: Lifeblood Activated on Lose Control");
                CastSpell("Lifeblood", Me, "");
                return RunStatus.Failure;
            })), new Decorator(ret => (((THSettings.Instance.ProfBuff == 5) && Me.Combat) && (HealWeight(Me) < THSettings.Instance.ProfBuffHP)) && CanCastCheck("Lifeblood", true), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Use: Lifeblood Activated on Low HP");
                CastSpell("Lifeblood", Me, "");
                return RunStatus.Failure;
            })), new Decorator(ret => ((((THSettings.Instance.ProfBuff == 6) && Me.Combat) && ((Me.CurrentTarget != null) && Me.CurrentTarget.IsValid)) && ((IsEnemy(Me.CurrentTarget) && !Me.CurrentTarget.IsPet) && ((GetDistance(Me.CurrentTarget) <= 5f) && (Me.CurrentTarget.HealthPercent < THSettings.Instance.ProfBuffHP)))) && CanCastCheck("Lifeblood", true), new Styx.TreeSharp.Action(delegate (object param0) {
                Styx.Common.Logging.Write("Use: Lifeblood Activated on Enemy Unit Low HP");
                CastSpell("Lifeblood", Me, "Use: Lifeblood Activated on Enemy Unit Low HP");
                return RunStatus.Failure;
            })) });
        }

        #endregion

        #region WriteDebug

        private static DateTime LastWriteDebug;

        private static Composite WriteDebug(string message)
        {
            return new Styx.TreeSharp.Action(delegate(object param0)
            {
                if (message != "")
                {
                    object[] objArray = new object[4];
                    objArray[0] = "(";
                    TimeSpan span = (TimeSpan)(DateTime.Now - LastWriteDebug);
                    objArray[1] = Math.Round(span.TotalMilliseconds, 0);
                    objArray[2] = ") ";
                    objArray[3] = message;
                    Styx.Common.Logging.Write(string.Concat(objArray));
                    LastWriteDebug = DateTime.Now;
                }
                return RunStatus.Failure;
            });
        }

        #endregion
    }
}